0

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')
        })
Lukas
  • 7,384
  • 20
  • 72
  • 127
  • `appendTo` is for inserting DOM elements: http://api.jquery.com/appendTo/ and is a method of jQuery objects, not strings. – Felix Kling Jul 30 '12 at 08:29

2 Answers2

2
$('#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);
});
Community
  • 1
  • 1
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164
0

Try appending the element itself:

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

Demo http://jsfiddle.net/AbeyT/

Esailija
  • 138,174
  • 23
  • 272
  • 326