Results 1 to 2 of 2
-
11-22-2011, 07:37 PM #1
Element Reference by Id Variable - JQuery
Element Reference by Id Variable - JQuery
If you need to get a reference to an element by a passed id variable, you could do that by
$("#"+variablename)
In this example below we set the class of an element in a function which recieves the id of element as a variable.
Code:function SetClass(elementId) { $("#"+elementId.addClass("myNewClass"); }
Webmaster Forum <--to the honor of webcosmoforums.com for having us this great place to hang out.
-
01-08-2012, 07:50 PM #2
Freshman
- Join Date
- Jan 2012
- Posts
- 10
- Thanks
- 0
- Thanked 1 Time in 1 Post
- Feedback Score
- 0
It is always best practice to include context with jQuery. This means calling the element (which you can do using ID).
This can really speed things up since it lessens the amount of the DOM tree javascript needs to search through.Code:$('#obj_id', '#obj_parent_id')
Similar Threads
-
Importent Element Of the Link Optimization
By neha parnami in forum Search Engine OptimizationReplies: 10Last Post: 08-11-2011, 07:39 AM -
Variable reference to a column in MS SQL
By DCSS in forum DatabasesReplies: 6Last Post: 12-29-2010, 08:49 PM -
Remove an Element in JavaScript Array
By JavaScriptBank in forum JavaScript & AJAXReplies: 0Last Post: 09-10-2010, 08:48 PM -
List Attributes of a HTML Element
By mastermind in forum Web Development - Programming & CodingReplies: 0Last Post: 12-19-2009, 04:13 PM -
Element “ScriptManager” is not a known element
By manik in forum ASPReplies: 0Last Post: 08-10-2008, 12:06 PM



Reply With Quote

