jQuery plugin to associate label “for” attribute with form controls that have dynamic id’s

For whatever reason, you can’t associate your labels with your form controls implicitly by wrapping both the label text and the control in a <label> element:

<label>
  Email address: <input type="email" name="email" value="" placeholder="you@example.com"/>
</label>

You’ve had to explicitly state the form control you want the label to be associated with:

<label for="email">Email address:</label>
<input id="email" type="email" name="email" value="" placeholder="you@example.com"/>

…but your framework has other ideas, it decides to commandeer your precious “id” attribute and change it from a simple and beautiful “email” into a junky “dnn_ctr1163_RegistrationForm_email”. *cough* DotNetNuke *cough*, but also *cough* Wicket *cough* and probably a whole load of others.

The problem is now that your label is no longer associated with your form control, and there isn’t a simple fix, like, for example, change the for attribute to read “dnn_ctr1163_RegistrationForm_email”, because the numbers in the id change each time you refresh the page. The ID is dynamic, and you are receiving accessibility black stars.

So, luckily I noticed that often the id will change, but the framework will leave your originally intended id somewhere in there. I’ve written a jQuery plugin to look at label for attributes and try to find the form control you intended to associate it with before your server side framework so rudely changed it.

How to use

  1. Download the plugin and add it to your page
  2. Select the labels you want to re-associate and call the function eg. $(‘label’).fuzzyFor();

TODO

The plugin finds matches by looking for input, select and textarea elements in the document and checking to see if the for attribute in your label element appears in the id attribute of the form control. At the moment if more than one match is found, it just uses the first (which is probably good enough for most). However, it should probably do something a bit more clever and use the form control that is closest to the label (I’m reasoning that you normally put your label’s close to your controls).

4,627 thoughts on “jQuery plugin to associate label “for” attribute with form controls that have dynamic id’s

  1. mexico drug store: My Mexican Pharmacy – order meds from mexico

  2. трансы пермь Погрузитесь в этот звуковой океан и позвольте себе унестись на волнах транса.

  3. WebP to PNG Hero is an easy online converter. It turns images into PNG files in seconds. You can use it if you need compatibility for design tools website uploads or client deliverables. This service helps you switch from WebP to PNG quickly. You do not need to install software or deal with settings. Just upload your file run the conversion and download a clean PNG. WebP to PNG Hero is built for speed and smooth workflows. It processes WebP to PNG conversions quickly and keeps the output sharp and accurate. The conversion preserves details clear edges and natural colors. This way icons graphics screenshots and photos look crisp after export. PNG is a choice for web publishing UI assets presentations or content creation. WebP to PNG Hero makes image conversion easy. It is useful for designers developers marketers or everyday users. It is a solution when platforms or apps do not fully support WebP. You may also want a more widely accepted format for editing and sharing. You can convert WebP to PNG online with confidence. Keep your visuals looking professional with a converter focused on speed quality and convenience. Use WebP to PNG Hero to convert WebP to PNG. It helps with image conversion needs. WebP to PNG Hero is a tool. WebP to PNG Hero best online image converter

  4. best price for viagra 100mg Sildenafil Price Guide buy Viagra online

  5. best price for viagra 100mg: Cheapest Sildenafil online – cheapest viagra

  6. JPG Hero Compress is a simple tool that you can use online to make your JPG files smaller. This is helpful when you are getting ready to put photos on a website or send them in an email. You can use JPG Hero Compress to make your pictures smaller so they load faster on the internet. The tool is made to be fast so you can get your pictures compressed quickly. You can even use it with a lot of pictures at the time. JPG Hero Compress tries to make your pictures smaller without making them look bad. It wants to keep your pictures looking sharp. The colors looking natural. JPG Hero Compress is a choice for people who want their image files to be smaller. When you use JPG Hero Compress to make your JPG files smaller it can help your website load faster. It can also help you save space on your computer and make it easier to upload your pictures to the internet. JPG Hero Compress is a tool to use when you want to compress JPG files online and you want to keep the quality of your pictures. You can use JPG Hero Compress to make your pictures smaller. It will be really easy to do. JPG Hero Compress online tool

  7. пицца саратов сайт «Додо Пицца Саратов» и «Ташир Пицца Саратов» – наши уважаемые конкуренты но мы уверены что наша «Пицца Саратов официальный сайт» представит весь спектр наших преимуществ.

  8. buy ivermectin pills: ivermectin lotion price – Ivermectin Access USA

  9. донна пицца саратов В Саратове Энгельсе и Балаково «Космопицца» — синоним «хорошей пиццы» и «отличной пиццы» будь то «пицца Малевич» или «Донна пицца».

  10. воронеж заказать пиццу на дом Откройте для себя мир восхитительной пиццы в Воронеже где каждая пиццерия предлагает уникальное меню способное удовлетворить даже самых взыскательных гурманов.

  11. WebP to JPG Hero is an online tool that helps you convert WebP images to JPG images quickly. You do not have to worry about the image quality. If you often download WebP files from the internet and you need to edit them or share them WebP to JPG Hero makes this easy for you. All you have to do is upload your image and then download the JPG image. The best thing about WebP to JPG Hero is that it is very fast. This tool is made to process your images so you can use them on your website or on social media. At the time WebP to JPG Hero makes sure that your images still look great after they are converted. The colors are still accurate. The details are still sharp. WebP to JPG Hero is great for people who create things like artists and writers and for people who market things. It is also good for teams of people who work together. You can use WebP to JPG Hero to make sure that your images can be used with any app or platform. This tool helps you get your work done quickly and easily. When you need to convert images to JPG images WebP to JPG Hero is a good choice because it works well and it is easy to use. WebP to JPG Hero is a tool for everyday use because it is fast and it makes sure that your images look great. WebP to JPG Hero online converter

  12. Institutional Crypto Trading Platform for Brokers and Crypto OTC Desk Operators Finery Markets is an institutional trading platform for digital assets offering a secure non-custodial ECN infrastructure for brokers market makers and Crypto OTC desk operators with access to aggregated liquidity and efficient trade execution. crypto ecn

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>