0

Тhis is code:

  if (urlGid) {
       $('.global_main').hide();
       $('#right-tabs, #right-tabs-content').show();
  } else {
       $('.global_main').show();
       $('#right-tabs, #right-tabs-content').hide();
  }

I think this is so trouble, how can change it elegantly?
can I code it without if else?

0

3 Answers 3

1

Yes, you can use toggle() for that. For example:

 $('.global_main').toggle(!urlGrid);
 $('#right-tabs, #right-tabs-content').toggle(urlGrid);

See docs here: http://api.jquery.com/toggle/#toggle-display

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

Comments

0

You can do this:

if (urlGid) {
    $('.global_main').hide();
    $('#right-tabs, #right-tabs-content').show();
} else {
    $('.global_main').show();
    $('#right-tabs, #right-tabs-content').hide();
}

Comments

0

Maybe just...

$('.global_main, #right-tabs, #right-tabs-content').toggle();

$( "#toggle" ).click(function() {
$('.global_main, #right-tabs, #right-tabs-content').toggle();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div id="right-tabs">right-tabs</div>
<div class="global_main" style="display:none">global_main</div>
<div id="right-tabs-content">right-tabs-content</div>
<button id="toggle">toggle</div>

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.