Friday, September 24, 2010

jQuery Basics / Fundamentals

Lets say we have following HTML code:

<input id="miteshvmehta-userControl1" name="miteshvmehta-userControl1" type="text"/>


To get element by ID

Javascript : var element = document.getElementById("miteshvmehta-userControl1");
jQuery : var element = $('#miteshvmehta-userControl1');



To get element by Name

Javascript : var element = document.getElementByName("miteshvmehta-userControl1");
jQuery : var element = $("input[name=miteshvmehta-userControl1]");

To fetch element based on multiple criteria, we need to separate criteria with blank space:
jQuery : var element = $("#myForm input[name=miteshvmehta-userControl1]");
This helps to look only in myForm id

No comments:

Post a Comment