Question

How to select a list of asp labels within a div?

<div id="myDiv"> <asp:Label ID="myLabel".../> <asp:Label ID="myLabel".../> </div>

This Jquery code does not work.

$("#myDiv label").each(function(){ alert("show this msg");});

Any assistance will be appreciated.

Was it helpful?

Solution

Try this:

$("#myDiv span[id*=myLabel]").each(function(){ alert("show this msg");});

Since, a asp:Label is rendered as span in HTML.

Also, please give some unique ID to the asp labels like myLabel1, myLabel2, etc.

OTHER TIPS

Try this:
u can iterate through all lables inside #mydiv.use ^ selector which check the starting string

$("#myDiv span[id^=myLabel]").each(function(){ alert("show this msg");});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top