views:

21

answers:

2

Hi guys, so I have a few links that have a class of 'button', and I am trying to get their text values with the jQuery .text() function, but it is returning nothing at the moment,

code:

$(document).ready(function() {

 var tester = $('a.test').text();

 alert(tester);
});

HTML:

<a class='test'>TEST</a>

any idea why this might not be working?

A: 

That code looks okay. Make sure you have referenced the jQuery js file, and that you don't have any errors elsewhere in your javascript.

Bennor McCarthy
Damn... too slow.
Bennor McCarthy
A: 

This code works, just try....

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
</head>
<body>
    <a class="test">Test</a>

  <p></p>
<script>
   var string = $("a.test").text();
   alert(string);
</script>

</body>
</html>
boss