Lukas
Lukas

Reputation: 7734

Append ID to some element from other element click action

i have a little problem with jQuery. I want to append ID for element from other element after that i click on it... :) So, if i click some list element this element id will go to another, can you hel me? This is my code...

        $('#main_menu li').click(function(){
            (this.id).appendTo('.main_content ul')
        })

Upvotes: 0

Views: 150

Answers (2)

Esailija
Esailija

Reputation: 140228

Try appending the element itself:

$('#main_menu li').click(function() {
    $(this).appendTo('.main_content ul')
});

Demo http://jsfiddle.net/AbeyT/

Upvotes: 0

thecodeparadox
thecodeparadox

Reputation: 87073

$('#main_menu li').click(function(){
  $('.main_content ul').attr('id', this.id);
});

Here this.id will get the clicked element id and set that id to .main_content ul.

But this will make id duplication, which is not allowed.

Instead of id you can make class:

$('#main_menu li').click(function(){
  $('.main_content ul').attr('class', this.id);
});

Upvotes: 2

Related Questions