How to add a title in anchor tag using jQuery?


To add a title in anchor tag in jQuery, use the prop() method. The prop() method is used to set properties and values of the selected elements.

You can try to run the following code to learn how to add a title in anchor tag using jQuery −

Example

Live Demo

<html>
   <head>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script>
       $(document).ready(function(){
         $("#button1").click(function(){
            $('.myClass').prop('title', 'This is your new title');
            var myTitle = $('.myClass').prop('title');
            alert(myTitle);
         });
       });
      </script>
   </head>
   <body>
      <div id='div1' class="myclass">
         <a class="myClass" href='#'><img src='http://tutorialspoint.com/green/images/logo.png' /></a><br>
         <button id="button1">Get Title</button>
      </div>
   </body>
</html>

Updated on: 13-Feb-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements