views:

1256

answers:

6

This is basic.

How do I get the value 'This is my name' of the above span?

<div id='item1'>
<span>This is my name</span>
</div>
+4  A: 
$('#item1 span').text() or $('#item1 span').html()

should do the trick I think

Lewis
Where do I find those jQuery functions?
Felipe Barreiros
From jquery docs.http://docs.jquery.com/Main_Page
rahul
http://docs.jquery.com/Manipulation
Boldewyn
Add some ` around your code bits.
Alex Bagnolini
+1  A: 
F.Aquino
you've changed the question! Your answer is right for your question, he was specifying the id not a class name
Lewis
well, if you see the first comment under his name you will notice that he did not write an attribute at all, it was <div 'item1'>, I guessed wrong apparently.
F.Aquino
+1  A: 

Assuming you intended it to read id="item1", you need

$('#item1 span').text()
Rich
A: 
$("#item1 span").text();
rahul
A: 

in java wouldnt you use getelementbyid('item1').innertext ?

Grumpy
my bad, he asked for jquery
Grumpy
A: 

$('#item1').text(); or $('#item1').html(); works fine for id="item1"

dipraj.shahane