Select a specific child of the current item using IT
I would like to know how to choose <span ="data">from the following.
<div class="feeds" onmouseover="...">
<div id="someDiv"></div>
<div class="moredivs"></div>
<span ="data">data in here...</span>
</div>
I would like to use something like: onmouseover="select(this)"and then have access to this range based on this event, because I have <div class="feeds">elements.
Even a jQuery suggestion is welcome.
The HTML you specified is not valid. When defining attributes, you must give them a name. Suppose you have this:
<span class="data">data in here...</span>
With jQuery, you can simply do this without a built-in event handler. In $(document).ready()you can put:
$('.feeds').mouseover(function () {
var $span=$('span.data', this);
});
$spanwill have access to yours span(in the jQuery collection).
jsFiddle Demo - jQuery version
Javascript ( : onmouseover="select(this)"), :
function select(me) {
var span=me.getElementsByClassName('data')[0];
}
getElementsByClassName() , , IE.
. .feeds, id someDiv, HTML.
- http://jsfiddle.net/4NAJ9/1/
<script>
$(function(){
$('.feeds').hover(function(){
var data_span = $(this).find('.data');
alert(data_span.html());
}, function(){
// If you wanted something to happen 'onmouseout', put it here
});
});
</script>
<div class="feeds">
<div id="someDiv"></div>
<div class="moredivs"></div>
<span class="data">data in here...</span>
</div>
jQuery, inline onclick .feeds.
Javascript HTML-. jQuery .