質問

I have 4 div's on the page with unique ID's. Example external link: www.website.com/page.html#one.

I need the display (set to none) to change to block. I'm at a bit of a loss (my JavaScript isn't very strong). Any ideas? Below is the code I'm using to parce the url, and the div id's are literally just one, two, three, and four.

$(document).ready(function() 
{
    var hashVal = window.location.hash.split("#")[1];

    $("#" + hashVal).style.display = 'block';

});
役に立ちましたか?

解決

There's no need to split the hash tag by the hash mark if you're going to use it as a selector. (see these docs)

And, for jQuery, you're looking for the css method i believe:

$(window.location.hash).css('display','block');
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top