Search code examples
javascriptjqueryhref

Find a href and match a div


I have this variabele.

var href = $(this).attr('href');

I get the href from a link. Now i have a lot of display none div's on the page. I want to check if the div have the same id. The id that is in the href. Then the div must be show.

How can i make that check?


Solution

  • Concatenate your href variable with a number sign to produce a jQuery ID Selector, and call .show() on your returned object:

    $('#' + href).show();