0

In the image below you can see there are 2 tabs:

  • All Task Activity tab
  • Comments tab

When the All Task Activity tab is clicked on, I need to change the CSS definition for the CSS class ".Activity-comment" to "display: block;"

When the Comments tab is clicked on, I need to change the CSS definition for the CSS class ".Activity-non-comment" to "display: none;"

So the goal is simple, both tabs will actually be showing the HTML DOM nodes for the same Div/Data. I will simply be showing/hiding records based on the clicked on tab.

enter image description here

Simple jQuery click event...

$('#task-modal-activity-comment-btn').click(function(e) {

    //  make CSS defintion for CSS class `.Activity-non-comment` 
    // = display: none;

    e.preventDefault();
});


$('#task-modal-activity-btn').click(function(e) {

    //  make CSS definition for CSS class `.Activity-non-comment` 
    // = display: block;

    e.preventDefault();
});

Based on my 2 jQuery click events above, how could I change the CSS definition for the mentioned CSS classes?

2
  • 1
    Are you sure you want to change definition? Usually such tasks resolve with adding/removing additional class wich change behavior Commented Jun 16, 2015 at 5:40
  • You can add a <style> element to the <head> that overrides the previously defined styles for the class. But in many cases it's easier to actually add a new class for affected elements. Commented Jun 16, 2015 at 5:41

3 Answers 3

2

Are you sure you want to change definition? Usually such tasks resolve with adding/removing additional class wich change behavior

$('#task-modal-activity-comment-btn').click(function(e) {

    //  make CSS defintion for CSS class `.Activity-non-comment` 
    // = display: none;

    $('.Activity-comment').removeClass('hidden');
    e.preventDefault();
});


$('#task-modal-activity-btn').click(function(e) {

    //  make CSS definition for CSS class `.Activity-non-comment` 
    // = display: block;
    $('.Activity-comment').addClass('hidden');
    e.preventDefault();
});

where 'hidden' is

.hidden { display: none; }
Sign up to request clarification or add additional context in comments.

1 Comment

You're right I read that right after making the post, thanks for posting it though so I dont have to delete
2

You could try this.

$('#task-modal-activity-comment-btn').click(function(e) {

//  make CSS defintion for CSS class `.Activity-non-comment` 
// = display: none;
$('.Activity-non-comment').css('display','none');
e.preventDefault();
});


$('#task-modal-activity-btn').click(function(e) {

//  make CSS definition for CSS class `.Activity-non-comment` 
// = display: block;
$('.Activity-non-comment').css('display','block');
e.preventDefault();
});

give the class that you need to display by default a display block at the time of dom ready. Refer the given link for more info on jquery css selectors Jquery CSS selectors

Comments

0

Please try the following code

$('#task-modal-activity-comment-btn').click(function(e) {

    //  make CSS defintion for CSS class `.Activity-non-comment` 
    // = display: none;
$('.Activity-non-comment').css('display','none');

    e.preventDefault();
});


$('#task-modal-activity-btn').click(function(e) {

    //  make CSS definition for CSS class `.Activity-non-comment` 
    // = display: block;
$('.Activity-non-comment').css('display','block');

    e.preventDefault();
});

1 Comment

you can use .style or .css() Also you should write into "style" attribute not into "display"

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.