The problem is not that difficult, I just can't get my head around it (noob at Jquery). The problem all es down to when clicking a <span>
getting it`s text and print it;
$('span').click(function(){
var t= ???;
alert(t);
});
How can i get it's text??? NOTE: Each span does not have an id or class, any span clicked must output a message. Each span is generated dinamic via PHP and I need it's value.
The problem is not that difficult, I just can't get my head around it (noob at Jquery). The problem all es down to when clicking a <span>
getting it`s text and print it;
$('span').click(function(){
var t= ???;
alert(t);
});
How can i get it's text??? NOTE: Each span does not have an id or class, any span clicked must output a message. Each span is generated dinamic via PHP and I need it's value.
Share Improve this question edited Jul 12, 2011 at 8:13 jensgram 31.5k6 gold badges83 silver badges100 bronze badges asked Jul 12, 2011 at 8:11 ka_linka_lin 9,4326 gold badges38 silver badges58 bronze badges4 Answers
Reset to default 10$('span').click(function(){
var t = $(this).text();
alert(t);
});
See a demo at jsFiddle.
$('span').click(function(){
var t= $(this).text();
alert(t);
});
See .text()
.
use .text() (http://docs.jquery./Text())
$('span').click(function(){
alert($(this).text());
});
To get the span id without click
id = $("span.ClassName").attr('id');