-2

I have one button with its corresponding ID. I wish to set the tooltip property of it with JS.

<button name="subject" id="button" type="submit" value="HTML" title="title1">HTML</button>

<script>   
function clickMe() {
    $('#button').title = 'title2';
} 
</script>

How am I able to do this ? Is it title property or some other ?

Thank you in advance

emerson.marini
  • 9,331
  • 2
  • 29
  • 46
Mefhisto1
  • 2,188
  • 7
  • 34
  • 73

4 Answers4

4

use prop function, as you are using jquery.

$('#button').prop('title', 'title2');

if using plain javascript (no jquery)

document.getElementById('button').title = 'title2';
SSA
  • 5,433
  • 4
  • 36
  • 50
2

You can simply set the title attribute by

$("#button").attr('title', 'title2');

Like this you can give/ define any attribute to html element.

vamshichalla
  • 141
  • 1
  • 1
  • 10
1
$( "#button" ).attr( "title", "title2" );
Manisha Patel
  • 354
  • 2
  • 12
0

var element = $('#yourElementId');

//Get or Set an element's title property with jQuery (v1.6+)

element.prop('title', 'your new title');

//Get or Set an element's title attribute with jQuery (versions <1.6)

element.attr('title', 'your new title');