html - Altering multiple input's id's using jquery -


i trying change id's of of check boxes inside of parent container, far have ot been able work, here code,

html:

<div data-custom='other_container' class='container'> <h3>other:</h3> <div class='container'>   <label for='monitoring'>monitoring , verification of energy savings: </label>   <div>     <input type='checkbox' name='other' id='monitoring' class='validate[mincheckbox[1]] checkbox' />   </div> </div> <div class='container'>   <label for='engineering'>engineering & project management: </label>   <div>     <input type='checkbox' name='other' id='engineering' class='validate[mincheckbox[1]] checkbox' />   </div> </div> <div class='container'>   <label for='energy_audits'>energy audits: </label>   <div>     <input type='checkbox' name='other' id='energy_audits' class='validate[mincheckbox[1]] checkbox' />   </div> </div> </div> 

jquery:

$("[data-custom='other_container']").children('input').attr('id', 'test'); 

any idea on wrong this?

thanx in advance.

the data-custom='other_container' element doesn't have children <input> elements.

you should use .find() instead.

$("[data-custom='other_container']").find('input').attr('id', 'test'); 

the .find() method search through descendants, whereas .children() looks @ immediate children.

but keep in mind ids must unique, want sure assign unique id each. this:

$("[data-custom='other_container']").find('input').attr('id', function( ) {        return 'test' + i; }); 

also, idea give div tag name in selector in case, jquery isn't looking @ every element data-custom attribute.

$("div[data-custom='other_container']") 

you make little more specific adding .container class selector.

$("div.container[data-custom='other_container']") 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -