-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

1
  • $('#button').attr('title') = 'title2'; or $('#button').prop('title', 'title2'); Commented Aug 22, 2014 at 12:29

4 Answers 4

4

use prop function, as you are using jquery.

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

if using plain javascript (no jquery)

document.getElementById('button').title = 'title2';
Sign up to request clarification or add additional context in comments.

Comments

2

You can simply set the title attribute by

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

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

Comments

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

Comments

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');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.