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.

Était-ce utile?

La 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.

Autres conseils

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");});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top