Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Jquery Selecting ID's

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #183755
    Gary Pickles
    Participant

    Hi All, I’m new to jQuery and have build a codepen for a hotel booking form that reveals sections of the form the more guest there are, worked fine in codepen, if you added number to adult, children and babies it adds them and reveals another section of the form.

    http://codepen.io/Garypickles/pen/jofvL?editors=101

    but when i moved it across onto my page, it stopped working, solved the problem, turned out my code would not select by ID if there was another in on the input.

    ID=”total” worked
    ID=”someotherid total” didn’t work

    can anybody explain why?

    My code works but looks a bit long winded, is there a shorter more elegant way to approach this? or for such a simple task is this OK

    #183762
    __
    Participant

    turned out my code would not select by ID if there was another in on the input.

    ID=”total” worked
    ID=”someotherid total” didn’t work

    can anybody explain why?

    Because “total” and “someotherid total” are not the same ID. If you need your code to select things with different IDs, use a .class or [data-attribute] selector instead.

    #183763
    __
    Participant

    MOD: dupe. please delete.

    #183765
    Gary Pickles
    Participant

    thank you, I was under the impression you could give multiple ID’s to one object by putting a space between them as you can with classes.

    #183785
    __
    Participant

    Nope. The id is the entire string.

    If you need class names for another purpose, you can use those. Otherwise, data-* attributes are most appropriate for what you’re doing.

    http://codepen.io/adrian-enspired/pen/akjhm

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.