开发者

How do I change the title of a link using jQuery

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 thing开发者_如何学运维s:

  1. url
  2. 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>


use html function:

$('#link').html(text);

or , if you are talking about the title attribute:

$('#link').attr('title','some title');


I think you need to use the HTML() method to change the content of the anchor tag. Here is the link to the documentation.


you can try this javascript only.

document.getElementById('link').innerHTML = "new title";

i think this will surly helpful to you..

Thanks.


If all these answers don't work for you then you should check:

  1. What element are you selecting and see if it's the correct one
  2. What variable are you assigning to the title(data[1].title)

I recommend using firebug in firefox or using the dev console in google chrome, anduse the console.log() function to log things so that you don't have to alert() them all the time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜