Title: jquery append link
Last modified: August 19, 2016

---

# jquery append link

 *  Resolved [carlla](https://wordpress.org/support/users/carlla/)
 * (@carlla)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/jquery-append-link/)
 * hello!
 * My new plugin use jquery to make a menu tree. It have to create dinamic elements.
 * But, when I create a link element, Jquery ignory the click event. I think the
   append function is creating text instead html elements.
 * I tried the code:
 *     ```
       jQuery(document).ready(function($){  
   
       // the top level menu - click event
       jQuery('.myclass').click(function() {
         var id = $(this).attr('name');
         alert(id);
         $('#mylist-'+id).append("<a class=\"myclass2\" href=\"#\" name=\"test\" > TEST </a>  ");
        }); // end click
   
       // the second level menu - event click
       jQuery('.myclass2').click(function() {
         var id = $(this).attr('name');
         alert(id);
       });
   
       }); //end jquery
       ```
   
 * When click in link (class=myclass) I need create a link (class=myclass2) and 
   it need to call a second function when clicked.
    The fist event worked well and
   create the element. But I didn’t get the second alert when click in the test 
   link (class=myclass2).
 * Someone have even tried to do something like that?

Viewing 1 replies (of 1 total)

 *  Thread Starter [carlla](https://wordpress.org/support/users/carlla/)
 * (@carlla)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/jquery-append-link/#post-1281293)
 * jQuery’s click event seems considers only the first click on page, no matter 
   how many links there are, only first click can run a function. It seems not happen
   to other html elements, only “a” element.
 * So use [jQuery’s live event ](http://docs.jquery.com/Events/live#typefn) instead
   click event when you are working with “a” elements and need to get the click 
   event.
 * I changed
 *     ```
       jQuery('.myclass').click(function() {
       ... });
       ```
   
 * to
 *     ```
       jQuery('.myclass').live("click", function() {
       ... });
       });
       ```
   
 * Now it works, and I could make my dynamic menu =)

Viewing 1 replies (of 1 total)

The topic ‘jquery append link’ is closed to new replies.

## Tags

 * [dynamic menu](https://wordpress.org/support/topic-tag/dynamic-menu/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [onclick](https://wordpress.org/support/topic-tag/onclick/)

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 1 reply
 * 1 participant
 * Last reply from: [carlla](https://wordpress.org/support/users/carlla/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/jquery-append-link/#post-1281293)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
