Possible Duplicate:
Can jQuery provide the tag name?
I want to display text inside the div tag in two different situations:
- When I hover over the first child element I want to see text as id and the name of the tag element.
- When I hover over the other elements (not first child) I want to see the text "this not first child".
HTML:
<ul id="ul1">ul1
<li id="aa">1</li>
<li id="bb">2</li>
<li id="cc"class="elm">3</li>
<li id="dd">4</li>
<li id="ee">5</li>
</ul>
<ul id="ul2">ul2
<li id="ul2-1">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul><br/>
<div>element-name</div>
CSS:
div,li{ width:40px; height:40px; margin:10px;
float:left; border:2px blue solid;
padding:2px; }
ul{ width:100px; height:10px; margin:10px;
float:left; border:2px blue solid;
padding:2px; }
span { font-size:14px; }
p { clear:left; margin:10px }
jQuery:
var $curr = $(".elm");
$curr.css("background", "#f99");
$("*:first-child")
.css("background", "#cac")
.hover(function () {
$(this).css("background","green");
$('div').text(this.id+$(this).tagname());
}, function () {
$(this).css("background", "#cac");
});