Kaur
Kaur

Reputation: 501

Jquery - APPEND is not a function

I am looking to find the html in first header in the page and add some html to it. Seems pretty simple but it is not working. I appreciate any help I can get. Thanks!

var str = $('h1:first').html();
$('h1:first').html(str.append("(<a class="dialogM" href="/alerts/alert1.html" title="Medical"><img src="/images/alert1.gif"></a>)"));

The error it is giving is - "TypeError: str.append is not a function"

Upvotes: 0

Views: 641

Answers (2)

castletheperson
castletheperson

Reputation: 33496

str is a string. Strings don't have an append method; they concatenate with +.

What you probably meant to do was:

$('h1:first').html(str + '(<a class="dialogM" href="/alerts/alert1.html" title="Medical"><img src="/images/alert1.gif"></a>)');

or even better:

$('h1:first').append('(<a class="dialogM" href="/alerts/alert1.html" title="Medical"><img src="/images/alert1.gif"></a>)');

Upvotes: 1

j08691
j08691

Reputation: 207973

.append() is a jQuery function that works on jQuery objects. You are passing a string str to it which won't work. Try:

$('h1:first').append('<a class="dialogM" href="/alerts/alert1.html" title="Medical"><img src="/images/alert1.gif"></a>');

jsFiddle example

Upvotes: 2

Related Questions