frequent
frequent

Reputation: 28513

How to mimic selecting e.target when only a Jquery object is available?

Odd...

I'm listening for an event like so:

$(document).on('some_event', 'div:jqmData(role="page")', function(e){
   console.log( e.target )
   })

In my console, I'm getting "hardcoded" HTML, like so:

<div id="profile" class="ui-page ui-body-c ui-page-header-fixed" data-role="page" data-url="some_url" data-external-page="true" tabindex="0">

I need to replicate this selection from another function in which I don't have e.target available. Instead I have the whole page element, which consoles as an object:

[div#profile.ui-page]

Question:
I'm missing some words here... how do I select the same way as e.target???

Upvotes: 0

Views: 77

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1075079

It sounds like when you say you have a "whole page object," you have a jQuery object wrapped around the DOM element. To access the raw DOM element, you index into the jQuery object (which is array-like), e.g., the first matched element in the jQuery object is at [0].

So:

var rawElement = pageObject[0];

Upvotes: 1

Related Questions