simple bit of jquery. I have a div with clss linklist, inside it has several linkbuttons
<script type="text/javascript">
$(function () {
$('#linklist a').each(function () {
alert(this.text);
});
});
</script>
I would assume that it should alert the text inside each rendered hyperlink. instead I am getting the value “undefined”
if i change it to
alert(this.id);
i am getting the correct client id – therefore i know at least that I am selecting correct.
why is this value undefined? same goes for this.text and this.value
Thanks
thisinside the event handler is the native DOM element.When you do
this.idyou are getting theidproperty of the DOMElement (an anchor). But it does not have atextproperty.To get the text of the anchor, use:
Or staying native javascript, you can: