doubleD
doubleD

Reputation: 536

add link title, if title is empty on <a> tag

Hi i have dynamically added list of links and title is added to the link but some of the link are add empty titles so i need to add a default title using JavaScript

<a class="tip visible-phone" data-original-title=" " href="#" data-toggle="tooltip" data-placement="right" title="">view</a>

Upvotes: 0

Views: 866

Answers (2)

user405398
user405398

Reputation:

$("a.tip.visible-phone[title='']").attr("title", "default title");

Upvotes: 1

Reinstate Monica Cellio
Reinstate Monica Cellio

Reputation: 26143

This should do what you need...

$("a[data-original-title=' ']").data("original-title", "default title");

or...

$("a[title='']").attr("title", "default title");

depending on whether it's the title attribute, or data-original-title.

Just add that line of code after you have dynamically created the links.

Upvotes: 4

Related Questions