I am using JQuery.live() functionality to trap 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.
views:
40answers:
3I used the above code in alert(), and it is showing blank text.
RPK
2010-01-20 13:01:10
+1
A:
$(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
Alex Bagnolini
2010-01-20 13:04:52
+3
A:
Add parenthesis to use the method.
This will get the text.
$(this).text()
This will set it.
$(this).text("New Text")
Brandon
2010-01-20 13:05:23