How to get the title attribute of a div element? 1


If you are trying to get the title attribute of any HTML element, then use the following Jquery code to alert or get the required title.

HTML CODE:

<div class='car' id='car' title='This is a div for cars!'>

    Displaying your favourite cars!

</div>

Jquery to alert title element on page load.

<script>

    $(document).ready(function() {

    var title_val=$("#car").attr('title');

    alert(title_val);

    });

</script>

OUTPUT:

 

This is a div for cars!

 

 

You can use this JQuery to alert the title on click as well.