如何使用jQuery更改链接的标题 [英] How do I change the title of a link using jQuery

查看:206
本文介绍了如何使用jQuery更改链接的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码:

      $('#link').attr("href",link) 
      $('#link').text(text)

如何更改使用jQuery链接的标题?我正在更改网址,但我无法编辑文字,我做错了什么?

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>

我想改变两件事:


  1. url

  2. title(如上所示)

我可以更改链接,但标题不会改变。我选错了。因此,有没有办法列出所有可用的attr?或者你能帮助我改变上面的文字标题吗?

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>


推荐答案

使用 html 功能:

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

或者,如果你在讨论title属性:

or , if you are talking about the title attribute:

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

这篇关于如何使用jQuery更改链接的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆