最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery change innerHTML of link based on href - Stack Overflow

programmeradmin1浏览0评论

I have the following html generated by a CMS for a tabbed element:

<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.

How can I do this with jQuery? Thanks!

I have the following html generated by a CMS for a tabbed element:

<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.

How can I do this with jQuery? Thanks!

Share Improve this question edited Jun 30, 2014 at 14:06 Pratik Joshi 11.7k7 gold badges44 silver badges73 bronze badges asked Jun 27, 2014 at 7:08 TheRealPapaTheRealPapa 4,5399 gold badges80 silver badges165 bronze badges 1
  • Try serverfault. (system administrators) or superuser. for your desktop machine problem from your deleted post. – Stein Åsmul Commented Jun 29, 2014 at 7:11
Add a ment  | 

4 Answers 4

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

Try

Attribute Equals Selector [name="value"]

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

$('a[href="#tabopen_tickets"]') will select the a tag with href attribute #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:

$(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"); Documentation can be found here

发布评论

评论列表(0)

  1. 暂无评论