Mathias B.
Mathias B.

Reputation: 353

jQuery - set button title

I want to change the title of a button using jQuery

<button id="pub2" class="pub2" title="ok">Bibtex</button> 
<script>Tippy('.pub2', {interactive : true})</script>

Also, I have a small paragraph to test

<p id="testP">
   text
</p>

To change the properties, I'm doing the following:

$(document).ready(function(){
   $("#testP").text("test worked");
   $("#pub2").attr("title", "new title not working");
});

Updating the text of the paragraph works just fine, but the title of the button won't change, why?

Upvotes: 2

Views: 3159

Answers (2)

Muhammad Rizwan
Muhammad Rizwan

Reputation: 49

Use this one: HTML:

<button id="pub2" class="pub2" title="ok"> Bibtex </button> 

Jquery:

$("#pub2").prop("title", "new title not working");

Upvotes: 0

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72289

Your code working fine:-

$(document).ready(function(){
    $("#testP").text("test worked");
    $("#pub2").attr("title", "new title not working");// you can use prop() also
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="pub2" class="pub2" title="ok"> Bibtex </button> 

<p id="testP">
 text
</p>

Note:-

You have this code under button

<script>Tippy('.pub2', {interactive : true})</script>

Try to remove it from there and add into you script code like below:-

$(document).ready(function(){
  $("#testP").text("test worked");
  Tippy('.pub2', {interactive : true})
  $("#pub2").attr("title", "new title not working");// you can use prop() also
});

Upvotes: 3

Related Questions