2

I have a div like this:

<div class="radio-wrapper content-box__row " data-gateway-group="direct" data-select-gateway="34434244"> SOME CODE HERE </div> 

I would like to hide this div with javascript by the element data-select-gateway. For example if data-select-gateway is 34434244 hide the div.

2 Answers 2

1

You can use the following code to hide the first one:

document.querySelectorAll('[data-select-gateway="34434244"]')[0].style.display = 'none';

For all the elements with data-select-gateway="34434244":

elems = document.querySelectorAll('[data-select-gateway="34434244"]');
for (var i = 0; i < elems.length; i++)
  elems[i].style.display = 'none';

For all those, just with data-select-gateway:

elems = document.querySelectorAll('[data-select-gateway]');
for (var i = 0; i < elems.length; i++)
  elems[i].style.display = 'none';
Sign up to request clarification or add additional context in comments.

Comments

0

If you want to hide the DIV and maintain the way the page looks otherwise, eg have the DIV still take up the height and width to not impact placement of other elements then set visibility:hidden instead of display:none.

document.querySelectorAll('[data-select-gateway="34434244"]')[0].style.visibility = 'hidden';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.