Thursday, November 11, 2010

Converting Jquery to DOM

Converting a jquery object o DOM object

var nodeObjsArray = $(".NodeClass").get();

The above script will fetch all DOM objects whose class name matches "NodeClass"
Note that it returns an array. To fetch each DOM element you will have to iterate through it. This hold good even if there is only one match you would get an array
with one DOM object in it


var nodeObjs = $(".NodeClass").get(0);

same as

var nodeObjs = $(".NodeClass")[0]


In the above script we are fetching the DOM object directly unlike the previous case

Converting DOM to JQuery Object

var domObj = document.getElementById("elementID");
var jqObj = $(domObj );

Reference
http://api.jquery.com/get/

No comments:

Post a Comment