0
 $(".menu dt a").click(function() {

 var clickedId = "." + this.id.replace(/^link/,"ul");

In the second line above, I want to replace id with class,

I tried

 var clickedId = "." + this.attr("class").replace(/^link/,"ul");

But the code above doesn't worked and showed me the following error in console

this.attr is not a function

Any hints how can I use a class instead of id ?

2
  • 1
    $(this), not this to have a jQuery object. this is a DOM element Commented Jan 24, 2014 at 12:13
  • wrap this as an jquery object $(this) instead Commented Jan 24, 2014 at 12:14

2 Answers 2

3

Did you mean

$(this).attr

instead of

this.attr

this in an event callback will return the HTML DOM element, to have a jQuery object, use $(this)

Sign up to request clarification or add additional context in comments.

Comments

0

also you can use this.className:

var clickedId = "." + this.className.replace(/^link/,"ul");
//-------------------------^^^^^^^^^--this way

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.