Programmer Programmer - 1 year ago 98
Javascript Question

Can not get DOM element in jQuery

I am trying to get DOM element from jQuery selector array.

var n = $(this).index();
$title = $(".title:not(.small)")[n];

Yet it only returns text and not DOM element as I want it to.
I want to get DOM element so i can get the elements position on the page and scroll to it.

$(this) = list element
.title = there are few elements on the page with class="title" and "title small".

Thank you

PS: I could not find anything similar on stackoverflow or anywhere on google. It could be that I don't know how to correctly google this "error".

Answer Source

Using the [n] notation is the same as .get(): it gets the underlying DOM element.

To get a jQuery selection, use eq():

$title = $(".title:not(.small)").eq(n);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download