0

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> 
2
  • also append is appending the stuff into your span element not after it Commented Feb 27, 2013 at 12:36
  • maybe it's just the . missing : $('.C1') to get the elements of class C1? Is that what you were trying to do? Commented Feb 27, 2013 at 12:37

6 Answers 6

6

You forgot a .:

$('span[itemprop="description"]').append($('.C1')); 
Sign up to request clarification or add additional context in comments.

2 Comments

@user580950 i said it too so why i am down-voted.??? even this will not work because it will get object not html inside of it..
@Dipesh Parmar Read the docs, you can use a jquery object as the argument.
1

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

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

Comments

1

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.

3 Comments

Does that even matter, the code works for what he tries to do. The question is not if this is valid HTML
@s.lenders: I was editing my answer when you replied. I had previously given an invalid answer as I thought this was a different question, so had to quickly edit it. And yes, invalid HTML does matter as it's bad practice and there's no need for it.
Also I'm not sure why this was downvoted, along with every other answer to this question...
0

Change the jQuery code to :

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

Comments

0
$('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.

1 Comment

explain down-vote..no matter if its not a HTML attribute but we can still select it...try it..it always works.
0

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.