Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQUERY Get value from <span> on click

The problem is not that difficult, I just can't get my head around it (noob at Jquery). The problem all comes 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.

like image 318
ka_lin Avatar asked Dec 05 '22 21:12

ka_lin


1 Answers

$('span').click(function(){
    var t = $(this).text();
    alert(t);
});


See a demo at jsFiddle.

like image 128
Brock Adams Avatar answered Dec 07 '22 11:12

Brock Adams