need some help wit ha tiny piece of js code

hi there,

I am trying to customize a theme and I'd like to hide comments and have them slide into view if someone clicks the show comments button.

so the comments are initially hidden via css: display:none;

after checkingn a few sites, this is not such a good idea, since users without js won't ever reach my comments.

the tutorial I use for hiding is this one:

then I found a suggested solution of hiding the comments via js so if a user has js turned of he will see the comments and those that have js will have to click to see them...

The suggested solution was:

If you are using JavaScript to show something, you should also use JavaScript to hide it

can someone help me out here with a line of code?

hiding with js also has the benefit of the hidden text getting indexed by google :wink:

  • Ovidiu
    • Code Wrangler

    ok, short version: how to hide a certain id or class with js on load?

    longish one:
    i.e. if the js script gets loaded it hides a certain element I specify. without any other interaction.
    basically I need the js script to inject a display:none; for the element I am talking about.
    the user can then click on a js link to make it visible again, but if he has turned js off he will still see it.

  • Ovidiu
    • Code Wrangler

    hah! I've done it on my own! loading this js script will hide the comments and only show them if a link wrapped in special code is clicked!!!

    myscript.js: `function ShowHide(){ $j("#comments-template").animate({"height": "toggle"}, { duration: 1000 });}
    document.write('<style media="screen" type="text/css">#comments-template {display: none;}</style>');

    link: <a onclick="ShowHide(); return false;" href="#"><?php comments_number('leave the first comment','one comment so far','% comments so far'); ?></a>

    if a visitor doesn't have js turned on, then the display:none for the comments is never loaded and he doesn't have to click to make them visible. also google will see the comments :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.