JQuery Append To Multiple Elements Fails

Viewed 16040

I'm trying to use jQuery's append() method to append common content to set of div's as follows:

$("#horizontal_menu").append(menu);
$("#vertical_menu").append(menu);

What I'm finding is that the content (in this case, menu) is getting appended to vertical_menu but not horizontal_menu. Does appending to one <div> preclude you from appending that content to another <div>?

4 Answers

I was experiencing a similar issue whereby I couldn't add the const removeLink via the normal .append() method. Using Nicks advice above I was able to get it working as such.

        const removeLink = $("<span class='removelink'/>").html("X").on('click', function() {
          $(this).prev().remove();
          $(this).remove();
          counter --;
        });

        $(removeLink).appendTo('.dogname-inputs, .dogage, .dogweight, .mealplan');
Related