开发者

Javascript alter display based on URL

开发者 https://www.devze.com 2023-03-30 15:29 出处:网络
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

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');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号