Reputation: 888
I'm trying to add a <hr>
element into a <td>
in jquery based on the class. I've managed to find the <td>
elements I want to append without a problem, but I can't add the html - the <td>
already contains some html, I want to append this on the end.
Here is what I'm trying:
<script>
$( document ).ready(function() {
var something = "something";
var element = $('td').filter(':contains(something)').html('<p>Hello</p>');
console.log(element);
});
</script>
Thanks
Upvotes: 0
Views: 6908
Reputation: 53
try appending..something like this... and make sure you're using the jquery library
var element =$('td').filter(':contains(something)').append('<p>Hello</p>');
Upvotes: 0
Reputation: 1407
Instead of using .html() you can use .append() which just added whatever you write into the end of the div.
Like this
$('td').filter(':contains(something)').append('<p>Hello</p>')
This will put hello after filtered <td>
You can also use .prepend() to add things to the begining of the div.
Upvotes: 4
Reputation: 4472
Take a look to this: https://jsfiddle.net/jo2t5yL0/1/
It's working with <td>
and .html()
Maybe you forget to include jquery lib?
Upvotes: 0