Basically, I want to assign an event handler to each page number (in a ul) in some sort of loop. Each list item has a certain class and a name attribute. I want to assign the event handler .click() and then inside access the name attribute. Thanks to anyone who responds/views this post, and I would be appreciative if you would also show how to access the name attribute.
I can access all the list items like this I think (accessing each individual one is another process I don’t know)
$('li[class|='pagelistitem'). //now I need to assign event handler and access 'name' attr
The above code selects all
lielements with aclassvalue with prefix “pagelistitem”. It attaches aclickevent listener to each element in that set, and in the event handler function, it gets thenameattribute of the clicked element.As mentioned in the comments, you could (and should, in this case) use
this.namerather than passingthisinto another jQuery object and calling theattrmethod. However, as you specifically mentioned getting the attribute in the question, I wanted to show you the use of the jQuery method.