开发者

Using Javascript to ONLY hide a link/txt/div

I have a site with a Javascript image viewer to enlarge my pics.

Therefore if you browse with JS enabled you dont have to see the link to another 开发者_C百科page witch shows the pics enlarged.

if JS is disabled you wont see my function to enlarge pics with javascript, but will see my link to the enlarged page.

I need a code to just hide the link. i keep finding TOGGLE switches.


Instead of hiding the link, just put it in noscript tags:

<noscript>
  <a href="/url">This link only shows up for those without javascript enabled</a>
</noscript>


usually what you need to do is to put your image inside a link that has both href and onclick attributes

<a href="www.mysite.com/link_to_my_big_image.jpg" onclick="showBigImage();return false;">
    <img src="my_small_image.jpg" alt="click me"/>
</a>

if JS is disabled, the onclick wont work, and if js is enabled the link wont redirect the page

Good Luck


what i do in those cases is setting a class named nojs on the body or the HTML. Then i remove it with javascript. Then you can use the following CSS to cover both cases:

.js .yourelement {
   display: none;
}

.nojs .yourelement {
   display: block;
}

With jQuery you can do:

$(function(){ $("body").addClass("js").removeClass("nojs"); });

Its how its done in the HTML5 boilerplate as well.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜