For example we have 2 button
First button
<button class="arguments variation-one">Some text</button>
– this button have dynamic classes like: variation-one, variation-two, variation-three, but class .arguments is static.
and Second button
<button class="simple">Other text</button>
I must hide second button if first button receiving class .variation-two, without on click events. By js, jQuery, or even css if its possible. Please help me.
Im find similar problem on this forum and solution was this script
$(document).ready(function() {
var $redTags = $('.lt-label');
if($redTags.hasClass(".lt-offline") {
$("#l-b-wrapper").hide();
}
}
I tried to interpret it to suit my task, but nothing worked for me
2
Answers
This will hide the second button if the first button has the
variation-one
class.Note that this runs when the page is first loaded. If you want to hide and show the second button dynamically when the first button’s class changes, you need to run the code every time it changes. Either put this in a named function that you call from all the places that change the first button’s class, or use
MutationObserver
to detect changes automatically.Check if there’s any buttons that has
arguments
andvariation-two
classes. If there’s, hide the second button withsimple
class.