开发者

Getting clicked label's text using JQuery

开发者 https://www.devze.com 2022-12-17 18:44 出处:网络
I am using JQuery.live() functionality to tra开发者_运维知识库p click event of any label in a <div>. But when clicked, I want to get the text of the clicked label. I tried $(this).text, but it d

I am using JQuery.live() functionality to tra开发者_运维知识库p click event of any label in a <div>. But when clicked, I want to get the text of the clicked label. I tried $(this).text, but it displays the entire code.


Add parenthesis to use the method.

This will get the text.

$(this).text()

This will set it.

$(this).text("New Text")

text() in the jQuery docs


$(this).text returns the code of the function named text.

You have to CALL the method, using:

  • var myText = $(this).text(); to get the text or:
  • $(this).text('some text'); to set it


$(this).val() should get the input value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号