Results 1 to 2 of 2
  1. #1
    mastermind's Avatar
    mastermind is online now Master
    Join Date
    Oct 2008
    Posts
    2,787
    Thanks
    104
    Thanked 158 Times in 94 Posts
    Feedback Score
    0

    Default 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.

  2. #2
    ScottAN is offline Freshman
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post
    Feedback Score
    0

    Default

    It is always best practice to include context with jQuery. This means calling the element (which you can do using ID).

    Code:
    $('#obj_id', '#obj_parent_id')
    This can really speed things up since it lessens the amount of the DOM tree javascript needs to search through.

Similar Threads

  1. Importent Element Of the Link Optimization
    By neha parnami in forum Search Engine Optimization
    Replies: 10
    Last Post: 08-11-2011, 07:39 AM
  2. Variable reference to a column in MS SQL
    By DCSS in forum Databases
    Replies: 6
    Last Post: 12-29-2010, 08:49 PM
  3. Remove an Element in JavaScript Array
    By JavaScriptBank in forum JavaScript & AJAX
    Replies: 0
    Last Post: 09-10-2010, 08:48 PM
  4. List Attributes of a HTML Element
    By mastermind in forum Web Development - Programming & Coding
    Replies: 0
    Last Post: 12-19-2009, 04:13 PM
  5. Replies: 0
    Last Post: 08-10-2008, 12:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Partners: BOSTON WEB DEVELOPER, LLC   |   WEBCOSMO CLASSIFIEDS