Reputation: 501
How can I find first h1 on a page and append more html to its html? I am trying something like this and it is giving me error -
var str = $('h1:first').html();
$('h1:first').html(str.append('some more html '));
Upvotes: 2
Views: 722
Reputation: 5953
.html() can take the function
as argument, and return from it current html
with added new html
.
$('h1:first').html(function(){
return $(this).html() + ' some more html';
});
Upvotes: 2
Reputation: 58
What about
$('h1:first').html($('h1:first').html() + 'some more html');
You can put the string on variable like your code
var str = $('h1:first').html();
$('h1:first').html(str + 'some more html');
Upvotes: 0