I want to get the text of a dynamically created label in javascript, which is created in jade. Here’s the jade:
- for( var i = 0; i < groupsName.length; i++ ) {
li
a(href='JavaScript:validation(this)')
img(src='/images/edit.png', width='60', height='60', style='margin:8px 10px 10px 20px;')
h3 #{groupsName[0]}
label(for='groupsId' , id='labelid'+i ) #{groupsId[i]}
a(href='/groupdetails') Edit
- }
And this is my javascript code:
function validation(val){
var valid=val.id;
alert(document.getElementById(valid).innerHTML);
}
Not sure if I’m interpreting your template correctly, but as long as the dynamic label is descendant of the anchor tag which triggers the validation this should work:
First replace the
hrefby anonclickotherwise thethisbeing passed will reference thewindow. The generated anchor tag should look like this:Then just adapt your function slightly:
Fiddle