How do I change the title of a link using jQuery
15,333
use html function:
$('#link').html(text);
or , if you are talking about the title attribute:
$('#link').attr('title','some title');
Comments
-
JZ. almost 2 years
Here is the code I have:
$('#link').attr("href",link) $('#link').text(text)
How do I change the title of a link using jQuery? I'm correctly changing the url, but I can't edit the text, what am I doing wrong?
<a id="link" href="" target="_blank">text</a> $('#link').attr("href",data[1].url) $('#link').attr("title",data[1].title) <a href="http://link.com">title</a>
I'm tring to simply change 2 things:
- url
- title (as show above)
I'm able to change the link, but the title won't change. I'm selecting the wrong trhing. Therefor is there a way to list all attr available to me? Or are you able to help me change the text title above?
Either answer is acceptable.
<div id="highlight" class="topicHighlight hero1"> <h3 id="h3">hero_1_large_text</h3> <p id="p"></p> <span id="coverTextSpan">hero_1_small_text</span> <a id="link" href="url" target="_blank">text</a> </div>
-
JZ. over 12 yearsI just want to change the word title: <a href="link.com">title</a> how do I do this?
-
Alex Pacurar over 12 yearsI think you are making a confusion between the title attribute and the html of a link tag... see w3schools.com/tags/att_standard_title.asp and w3schools.com/jsref/prop_html_innerhtml.asp .... so, if you want to change the link`s html (the displayed text) you need to change the innerHTML property for that link (jquery offers a wrapped function : see api.jquery.com/html