2

I have this code.

CSS

body {
    font-family:Verdana, Geneva, sans-serif;
    font-size:14px;
}

.slidingDiv {
    height:300px;
    background-color: #99CCFF;
    padding:20px;
    margin-top:10px;
    border-bottom:5px solid #3399FF;
}

.show_hide {
    display:none; 
}

HTML

<a href="#" class="show_hide">Show/hide</a>
<br />
<div class="slidingDiv">
    Fill this space with really interesting content.
    <a href="#" class="show_hide">hide</a>
</div>

JS

$(document).ready(function(){
    $(".slidingDiv").hide();
    $(".show_hide").show();
    $('.show_hide').click(function(){
        $(".slidingDiv").slideToggle();
    });
});

Someone tell me if its possible to add in this jquery function that if i click on it, at the same time to show/hide a new div, change a class to an tag and remove another class from another tag? How can i do it?

Thanks.

1
  • Are the tags related in any way hierarchically? If so, yes. If not, no. Commented May 18, 2012 at 18:44

4 Answers 4

6

yes you can, take a look of the method addClass and also of the removeClass.

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

3 Comments

... and removeClass, and JQuery documentation in general :)
Hi, thanks for your answers, but how can i apply this one to a specific menu>li>id="name" ?? Like this? $('#menu li name').removeClass('classname'); Thanks.
open a new Question and asked for that doubt that you have
5

remove: jQuery('element').removeClass('class'); reference
add: jQuery('element').addClass('class'); reference

And you can use toggleClass to switch.
toggle: jQuery('element').toggleClass('class otherClass'); reference

1 Comment

Hi, thanks for your answers, but how can i apply this one to a specific menu>li>id="name" ?? Like this? $('#menu li name').removeClass('classname'); Thanks.
3

Add class:

$('selector').addClass('className');

Remove class:

$('selector').removeClass('className');

2 Comments

Hi, thanks for your answers, but how can i apply this one to a specific menu>li>id="name" ?? Like this? $('#menu li name').removeClass('classname'); Thanks.
just use the name attribute as selector. $("name=['the name']")
1

yes of course you can add or remove classes

<script type="text/javascript">
$("#ButtonId").click(function () {
    $('#itemid').removeClass('classname');
    $('#itemid').addClass('classname');
});
</script>

Comments

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.