Get one element title and add this to another div in jquery

Just take the title attribute from the item clicked $(this) using .attr('title') and place the text in the div using .html() or .text():

$('a.myClass').click(function(){
    $('#firstDiv').html($(this).attr('title'));
});

The only reason to use e.preventDefauilt() is if the page can scroll down, as a # bookmark link will spring to the top:

$('a.myClass').click(function(e){
    e.preventDefault();
    $('#firstDiv').html($(this).attr('title'));
});

Browse More Popular Posts

Leave a Comment