0

New to jquery. I'm trying to show/hide function with link, but its not working completely. is it loading problem? I need

<a href='127.0.0.1/example/1' class='show_hides1'>click me</a>

Not

<a href='javascript:void(0);' class='show_hides1'>click me</a>

have any Idea? Suppose, I stay in 127.0.0.1/example and I need to go 127.0.0.1/example/1 and steel need show/hide. both page has my hide content. how can I do that?

3
  • 5
    what do you mean? what exactly do you want to happen? Commented Aug 4, 2013 at 19:24
  • 2
    IOW, you want to update the URL to a shown/hidden version of the page when the user clicks that thing, but without actually reloading the page? Commented Aug 4, 2013 at 19:36
  • yea, I want this, is it possible? Commented Aug 4, 2013 at 19:43

1 Answer 1

1

To show/hide elements using jQuery, use the following:

$(document).ready(function() {
    $(".show_hides1").click(function() {
        $("<somethingtoshoworhide>").toggle();
    });
});

Also, remove the href entirely, or also add return false; to the end of your click function so that it does visit the specified href page.

Sign up to request clarification or add additional context in comments.

2 Comments

Well said, I personally would create a CSS class with only display:hidden and then use jQuery toggleClass in the event handler.
Yeh, I'm kind of with you in that camp in all fairness, I love a good .hidden class over inline-styling :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.