javascript - select html object without id -


edit: 1 missing piece of information - can't use class selector because there more divs same class. thought of that, forgot mention it. have no idea why post got downvoted, seems awfully silly considering provided lot of information, gave honest effort, , tried verbose code examples. people on forum ridiculous sometimes.

i'm trying set id of div doesn't have 1 , there's no way can give 1 upon generation of page. i've tried using jquery (.each, .contains, .find, .filter, etc.) , can't seem right. know ton of people have asked question, none of answers made sense me.

i have ability set text (html?) of div, nothing else. ends looking this:

<div class="dhxform_note" style="width: 300px;">remaining letters: 500</div> 

i want handle div object can show user how many more letters can type updating text.

using this:

$("div") 

returns list of divs on page. can see target div in list, can't jquery return single object.

i know can done this:

var divs = document.getelementsbytagname("div"); for(var = 0; < divs.length; i++) {     if( /^remaining letters/.test(divs[i].innertext) )         divs[i].id = "kudosmsgnote"     } } 

but hoping complete cleaner looking solution involving jquery. want know how jquery, aesthetics not withstanding.

for situations there multiple divs class dhxform_note , not know exact location of said div:

$("div.dhxform_note").each(function(){     var text = $(this).text();     if(/^remaining letters/.test(text)){         $(this).attr("id", "kudosmsgnote");     } }); 

example

if, however, know div 2nd occurrence of dhxform_note can following:

$("div.dhxform_note").get(1).id = "kudosmsgnote"; 

example

or contains search:

$("div.dhxform_note:contains('remaining letters')").first().attr("id", "kudosmsgnote"); 

example


Comments