Treehouse: Grow your CSS skills. Land your dream job.

css id and onClick

  • # November 16, 2012 at 10:53 am


    I have a row of 4 blocks, set up with php all have same id called “Option”, and have a onClick function.
    When you click it the number shows up which one you clicked… but only the first one ever changes

    here is the link – do a view source to see code.

    so, any help on how I make the actual ‘block’ you click change colour and not just the first one all the time….

    I know this can be done if I have id=”option1″ id=”option2″ etc… but I am trying to avoid this and have just
    one id, but somehow change the colour of the one that is selected.

    thanks so much for reading!


    # November 16, 2012 at 11:13 am

    ID’s are only to be used once…which is where you are probably going wrong.

    Try creating a class that will do the same thing and then add that using JS.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.