Results 1 to 4 of 4

Thread: Various Ways of Using The Selector

  1. #1
    Join Date
    Sep 2013
    Location
    United Kingdom
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Various Ways of Using The Selector

    Hello people, I'm new to this forum. I was a member of stack overflow for a while, but the account eventually got suspended for what they thought was a mis-use of information - because of that harsh environment, I google'd an alternative. This seems like a brilliant one.

    Basically, when it comes down to the crunch - I really do consider myself a Designer and not a Developer. Although my skills are adequate(especially now I've noticed I can code better than I can spell 'adequate' - I got there on the fifth attempt). So, anyway this post - Some of the ways you can use the Javascript/jQuery selector and one I'm not familiar with, at all.

    so, we have the body and container elements;
    Code:
    <body>
    <div id="container"></div>
    </body>
    and we need to manipulate the DOM, specifically the container ID;

    #1
    Code:
     $('#container').append("The first insance");
    #2
    Code:
     $('body > div').append("The Second Instance");
    #3
    Code:
     $('body #container').append("The Third Instance");
    #4
    Code:
     $('div#container').append"(The Final Instance");
    OK, so you're probably thinking "There's more than that." .....

    #2 is structure dependant - the selector is assuming you have
    Code:
    <div id="container">The First Instance</div>
    directly below the body tag. If you do not, the selector will return the div that is.

    So, we may or may not know that the variations are available because each one will suit the needs which the page requires and some can be a benefactor for speed.

    but, what is this?

    Code:
    $('#'+VAR)
    var is a stored variable of sorts. if you are familiar with this syntax, you can probably use your imagination to complete the variable.

    anyway, thanks for reading. I'm usually a silent stalker of code, I pulled out something relatively mondane, making the effort for my introduction, 'yano?
    Thank you.
    .

  2. #2
    Join Date
    Sep 2013
    Location
    United Kingdom
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Looking at this now, I thought this would be something like Grab all ID's for every div and append whatever the Variable has stored; on the condition the selector within the variable is relating with $(this) and not something linear.

    what are your thoughts, I'd love to read them. .

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Welcome to DD.

    After reading your post, I'm not sure if you actually have a question or not. If you do, please explain.

    If you are looking to start an open-ended discussion, let me know and I can move your thread to the General Discussion forum.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,030
    Thanks
    44
    Thanked 3,211 Times in 3,173 Posts
    Blog Entries
    12

    Default

    With:

    Code:
    $('#'+VAR)
    VAR cannot be a variable of sorts. It's either a string variable or it's not. If it is, it will select the element with that id if there is one. Say VAR = 'container', then it will select that div from your previous post. If VAR is not a string variable, there will either be an error or nothing will be selected. If it is a string variable and there is no element with that id, there will be no error and nothing will be selected. If there are more than one elements with that id, generally it will select the first. In some circumstances/browsers though it will throw an error. In other circumstances (regardless of browser) it might select all of them, these last two possibilities are rare.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Is it possible to process my form in two ways?
    By theemorgandorfer in forum ASP
    Replies: 3
    Last Post: 06-10-2010, 07:27 PM
  2. Ways to post in here
    By BLiZZaRD in forum Flash
    Replies: 2
    Last Post: 08-26-2006, 02:03 PM
  3. Replies: 6
    Last Post: 04-06-2006, 03:23 PM
  4. AnyLink Drop Down Menu - Tried all possible ways
    By affu2000 in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 12-19-2005, 04:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •