views:

39

answers:

3
<ul id='ulid'>
<li>Task1</li>
<li>Task2</li>
<li>Task3</li>
<li>Task4</li>
<li>Task5</li>
<li>Task6</li>
<li>Task7</li>
</ul>
<div id="show_details"></div>

I would like what's the JavaScript that I can use to copy the details of the li into the div on mouseover hide it on mouseout.

+1  A: 

If you mean the "content" with "details", you might want to try:

var $details = $('#show_details');
$('ul > li').hover(function(){
   $details.text($(this).text());
}, function(){
   $details.text('');
});

Ref.: .hover()

jAndy
Hi jAndy, thanks for the code, but there are more than one ul elements are there, And I want to get the details from a particular ul, please elaborate how can I proceed for that. thanks
dave
@dave: to only execute the code on a particular `ul`, you need an unique identifier which should be created via the `ID` tag. So you HTML code should look like `<ul id="mylist">` which can be queried by `$('#mylist')`.
jAndy
Hi jAndy, can you give me the exact code, because i m not able to get the desired results. Thanks
dave
I got the correct which I was looking for. Thanks jAndy
dave
+1  A: 

Ref : jQuery.hover() , jQuery.html() , jQuery.empty()

$(function() {
 $('li').hover(function() {
    $('#show_details').html( $(this).text() );
  }, function() {
    $('#show_details').empty()
 });
});
Ninja Dude
Hi Avinash, thanks for the code, but there are more than one ul elements are there, And I want to get the details from a particular ul, please elaborate how can I proceed for that. thanks
dave
Ninja Dude
+1  A: 

This will work for a particular ul:

jQuery(document).ready(function(){

 $('ul#ulid li').hover(function() {
    $('#show_details').html( $(this).text() );
  }, function() {
    $('#show_details').html( '' );
 });

});

Demo

NAVEED
Thanks Naveed, it's working as expected.
dave