Select HTML elements inside another with jQuery

2

Let's say that I have a function defined in JQuery, I write it in a simplified way:

miFunc = function(elem) {
    ...
}

elem is an HTML element. It could be a past element when making the call for some mouse event. For example, a div element with the onmouseover attribute, as in the following code.

<div class"unaClase" onmouseover="miFunc(this);">
    <span class="otraClase"> ... </span>
</div>

Having elem , how could I access the elements that have the class otraClase and are within elem ? For example, for the code shown, select the element span to modify its content.

Obviously I am looking for something dynamic and these examples are concrete cases. The elements might not be span and there could be several (or even none).

    
asked by Uexkull 16.02.2016 в 17:33
source

1 answer

5

If you know that elem is an HTML element, decorate it with $() and filter from it:

miFunc = function(elem) {
    var otraClaseElems = $(elem).find(".otraClase");
}
    
answered by 16.02.2016 / 17:37
source