I have an form input element and want to change its title attribute. This has to be easy as pie, but for some reason I cannot find how to do this. How is this done, and where and how should I be searching on how to do this?
This question is related to
jquery
forms
attributes
Another option, if you prefer, would be to get the DOM element from the jQuery object and use standard DOM accessors on it:
$("#myElement")[0].title = "new title value";
The "jQuery way", as mentioned by others, is to use the attr() method. See the API documentation for attr() here.
If you are creating a div
and trying to add a title
to it.
Try
var myDiv= document.createElement("div");
myDiv.setAttribute('title','mytitle');
In jquery ui modal dialogs you need to use this construct:
$( "#my_dialog" ).dialog( "option", "title", "my new title" );
I beleive
$("#myElement").attr("title", "new title value")
or
$("#myElement").prop("title", "new title value")
should do the trick...
I think you can find all the core functions in the jQuery Docs, although I hate the formatting.
jqueryTitle({
title: 'New Title'
});
for first title:
jqueryTitle('destroy');
As an addition to @C??? answer, make sure the title of the tooltip has not already been set manually in the HTML element. In my case, the span class for the tooltip already had a fixed tittle text, because of this my JQuery function $('[data-toggle="tooltip"]').prop('title', 'your new title');
did not work.
When I removed the title attribute in the HTML span class, the jQuery was working.
So:
<span class="showTooltip" data-target="#showTooltip" data-id="showTooltip">
<span id="MyTooltip" class="fas fa-info-circle" data-toggle="tooltip" data-placement="top" title="this is my pre-set title text"></span>
</span>
Should becode:
<span class="showTooltip" data-target="#showTooltip" data-id="showTooltip">
<span id="MyTooltip" class="fas fa-info-circle" data-toggle="tooltip" data-placement="top"></span>
</span>
Source: Stackoverflow.com