nicker nicker - 1 year ago 85
Javascript Question

Jquery how to use $(this) to get value of clicked item?

I have trouble getting value of particular item that I'd clicked

<script src=""></script>
<p>test 1</p>
<p>test 2</p>

  • I'd tried
    , but it will return the value of 1st button("Yes) even if I clicked the 2nd button("No")

  • Same for
    , will return value of 1st

  • How do I use
    to get the value of item I clicked?

  • Don't suggest me to insert class or id, I'm not suppose to touch the html.

  • Please assist, thanks.

Answer Source

It is because $(this).click event listener is added to document object and not any specific html element.



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download