Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Append() Method in jQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 378
    Comment on it

    In jQuery append() method is used to add particular content at the end of the each element.

    In the below example, with the help of append method we will display the current text/content on hover of that.

     

    HTML-

    <h2>Hover over the elements</h2>
    <ul>
      <li class="link">
        <span>Html</span> <!-- Here we have to hover to see the append method effect -->
      </li>
    
      <li class="link">
        <span>CSS</span>
      </li>
      
      <li class="link">
        <span>JavaScript</span>
      </li>
    </ul>

     

    CSS-

    li{
        text-decoration: none; 
        position: relative;
      }
      .hover{ /*styling the position of the element to be shown on hover*/
        position: absolute;
        top: 10px;
        left: 40px;
        background-color: #fff;
        border:1px solid #ccc;
        padding: 5px 10px;
        display: none;
      }
      li.link:hover .hover{ /*displaying the element on hover*/
        display:block;
        z-index: 1;
      }

     

    JavaScript-

    $('.link').one('mouseover', function() { // on mouseover of li
         var original = $(this).text();// value/text of li will be saved in variable "original"
            $(this).append('<div class="hover">'+original+'</div>'); //that text will be append on hover div
        });

     

    Below is the link of above code:-

    https://jsfiddle.net/rxduswt6/2/

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: