php - How to toggle elements with javascript
304
Solution:
I would write them both to DOM and usetoggleClass()
from jQuery
<?php
$incl = $product->get_price_including_tax();?>
<div >
<p id="excl" ><?php echo $product->get_price_excluding_tax();?> excl.</p>
<p id="incl" ><?php echo $incl;?> excl.</p>
</div>
<button type="button">Click Me!</button>
With following CSS:
.mycont > .price.incl {display: none}
.mycont.show_incl > .price.incl {display: block}
.mycont.show_incl > .price.excl {display: none}
And jQuery:
$('button').on('click', function(){
$('.mycont').toggleClass('show_incl');
});
If you want to do it in pure javascript, I would suggest to call a functiononClick
event on button, and toggle class like stated here
Answer
Solution:
The conditional (ternary) operator is the only JavaScript operator that takes three operands. This operator is frequently used as a shortcut for the if statement[Reference]
Note: Do not mix-up your logic in markup. You should have a separate function for that.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: git was not found in your path, skipping source download
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.