1,105,391 Community Members

Convert DOM object to jQuery object?

Member Avatar
Dani
The Queen of DaniWeb
20,566 posts since Feb 2002
Reputation Points: 1,356 [?]
Q&As Helped to Solve: 931 [?]
Skill Endorsements: 204 [?]
Administrator
Featured
Sponsor
 
0
 

How can I convert a DOM node to a jQuery object? I am using a javascript library that is returning a DOM node. I don't know any of its properties. I want to convert it to a jQuery object so that I can work with it.

Member Avatar
singh1720
Newbie Poster
14 posts since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

hi Queen,

Convert DOM object to jQuery object is made by attaching it in a selector

  • .jquery,.context,.length,.selector these are some properties of jQuery object.
  • jQuery Objects that are return or created by jQuery()
    .

  • Every DOM object is a Node.(except one or two or more).

  • The DOM object is the “regular” un-wrapped object you can get without jQuery
  • Dom Elements that are retrieved. Example document.getElementById();
  • .name, .value are properties of Dom object.

So we can covert each other

//From jQuery object to Dom:
var domobject = jqueryObject.get();

//From Dom to jQuery object
var jqueryObject = jQuery(domobject);

Example:

//From Dom to jQuery object
var overlayContent = document.createElement("div");

The keyword this tells to the DOM element to which the handler is bound, so ‘this’ is not a jQuery object, but it just one step away from making it into jQuery by using $(this).

Member Avatar
Troy III
Practically a Posting Shark
891 posts since Jun 2008
Reputation Points: 174 [?]
Q&As Helped to Solve: 119 [?]
Skill Endorsements: 10 [?]
 
0
 

I'm not being able to understand what would "jQuery Object" mean exactly, since I don't use it. But...

I suppose that when referenced upon - these jq., dom objects - are somehow wrapped by it enabling you to use few or more extra methods not available on DOM api, - than the quickest run about might be by setting its "display" property to 'none' and perhaps give it an ID before appending it to the document so you can create a jQ handle for it with a conventional jQuery call as with any other element.

It's a workaround, but might serve you well until some other more direct route is found.
This is, of course - in case that the code from above didn't work for you.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article