Saurabh Kumar
Saurabh Kumar

Reputation: 16651

How i can set the span id text which is within a "a" element

HTML

 <a href="#" id="popp" name="popo" class="tooltipLink">
  <img  src="images/information.png" alt="info" />
  <span  class="tipp"></span>
 </a>

jQuery

var text = blah;
$('#popo span').text(text); 

The text is not setting...I am doing something wrong..?

Upvotes: 1

Views: 438

Answers (5)

ShankarSangoli
ShankarSangoli

Reputation: 69905

Try this:

var text = "blah";
$('#popp span').text(text);

Upvotes: 0

Dejan Marjanović
Dejan Marjanović

Reputation: 19380

$('#popp span.tipp').text(text);

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

You probably meant:

var text = 'blah';
$('#popp span').text(text);

as seen in this live demo.

Things to notice:

  • blah is wrapped inside quotes as it represents a string
  • use #popp instead of #popo as id selector

Upvotes: 0

Quentin
Quentin

Reputation: 943157

  1. Your selector matches a span inside the element with the id 'popo', which does not exist (popp != popo).
  2. You are trying to assign the value of text which is a copy of blah which is undefined

Upvotes: 0

Shadow Wizard
Shadow Wizard

Reputation: 66389

Typo and lack of quotes.. this will work:

var text = "blah";
$('#popp span').text(text);

First, by having this: var text = blah; you assigned the text as undefined variable and second you used the name instead of the ID of the anchor.

Upvotes: 2

Related Questions