jquery selector


Im trying to create a onclick event that targets an element, grabs its id and uses that id to target an element with the same class. However, it doesnt work - any ideas?

function is:

$("#partners .item").click(function(){
  var el = $(this).attr("id");
Who is Participating?
Chris StanyonConnect With a Mentor Commented:
Sorry - cross posted there :)

Your code is working but it looks like there is no elemet to add the class to. Say you click on an item with an ID of item5, you code will try and add a class to an element with a class of item5, but there are none on your page.
GaryConnect With a Mentor Commented:
The code works fine, we need the html as well to debug
coolispaulAuthor Commented:
Hi Garyc123

That's odd . example of mine is here:

if you click the image logos under "partners"  it should display a sepererate area but it doesnt seem to work..

Chris StanyonCommented:
You need to be a little clearer in your explanation. 'It doesn't work' is not very helpful. Does the click work, do you get the console output, does the .item actually have an ID.

As Gary says, there's nothing wrong with the code you've posted but it has no context, so we're left guessing!
coolispaulAuthor Commented:
blimey - as easy at that!

Thanks guys i didnt even spot that - called it "text1", "text2" etc instead of "item1..."

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.