TSCAmerica.com
TSCAmerica.com

Reputation: 5417

.Append not working

What i am trying to do is append the Table and its contents after *test123 that is before </span> tag is closed, but its not working, not sure what is wrong in this code ?*

JQUERY CODE

$('span[itemprop="description"]').append($('C1'));

HTML CODE

  <span itemprop='description'>test123</span>
        this is outside of span tag<br>

     <table width="200" border="1" class="C1">
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>

</table>

Upvotes: 0

Views: 160

Answers (6)

s.lenders
s.lenders

Reputation: 1149

You should append the html, not the object. You can do like this:

$('span[itemprop=description]').append($('.C1').html());

Upvotes: 0

James Donnelly
James Donnelly

Reputation: 128856

itemprop isn't a valid HTML attribute. I'm not sure if jQuery would allow this to work in the first place. You'll want to use data-itemprop instead.

$('C1') suggests you have an (again invalid) <C1> element. You need to use $('.C1') to select on the class.

Upvotes: 1

Dipesh Parmar
Dipesh Parmar

Reputation: 27382

$('span[itemprop="description"]').append($('.C1').clone());

You missed to define class in selector add . . Also you are appending Object to span not a html so i used .clone and its works for me.

Upvotes: 0

Mandeep Pasbola
Mandeep Pasbola

Reputation: 2639

Change the jQuery code to :

$('span[itemprop="description"]').append($('.C1'));

Upvotes: 0

Matt Cain
Matt Cain

Reputation: 5768

You forgot a .:

$('span[itemprop="description"]').append($('.C1'));

Upvotes: 6

Jeff Shaver
Jeff Shaver

Reputation: 3355

C1 isn't a valid selector. you need to use

$('span[itemprop="description"]').append($('.C1'))

Upvotes: 1

Related Questions