简体   繁体   English

jQuery基于href改变链接的innerHTML

[英]jQuery change innerHTML of link based on href

I have the following html generated by a CMS for a tabbed element: 我有一个CMS为标签元素生成的以下html:

<li class="active" style="width: 233px;">
  <a href="#tabopen_tickets">Open Tickets</a>
</li>

I want to change the link's text of "Open Tickets" to other text, but I only know the link's href . 我想将link's “打开票证”文本更改为其他文本,但我只知道链接的href

How can I do this with jQuery? 我怎么能用jQuery做到这一点? Thanks! 谢谢!

$('a[href="#tabopen_tickets"]').html('your new value');

Try 尝试

Attribute Equals Selector [name="value"] 属性等于选择器[name =“value”]

$('a[href="#tabopen_tickets"]').text('Changed');

$('a[href="#tabopen_tickets"]') will select the a tag with href attribute #tabopen_tickets" $('a[href="#tabopen_tickets"]')将选择带有href属性a标签#tabopen_tickets"

You can use: 您可以使用:

$('li.active a').text("new text here");

if you want to get it by href then use attribute equal selector: 如果你想通过href得到它,那么使用属性相等选择器:

$(a[href="#tabopen_tickets"]).text("new text here");

You can select link with jquery that contains, start or end with some text like this var link = $('a[href*="#tabopen_tickets"]') and then change the link text like link.innerHTML("new text"); 您可以选择包含jquery的链接,包含,开始或结束一些文本,如var link = $('a[href*="#tabopen_tickets"]')然后更改链接文本,如link.innerHTML("new text"); Documentation can be found here 文档可以在这里找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM