anyone can help me on a things , I have in a page once <nav class='test'> and below a <div> without any class/id, I want to hide/remove <div> element which is in next of <nav> tag , I can do $('.test').next().remove(); but strictly jQuery is not allowed , please give me any trick of JavaScript or CSS, Please note that , i haven’t access to edit any html code only i can add js/css.
Code is looking like this:-
<body class='home'>
<nav class='test'></nav>
<div>Want to remove this elements</div>
</body>
Thanks in advance.
Use querySelector with css adjacent sibling or next-sibling selector.
var ele = document.querySelector('.test + *')
ele.remove();
// or for older browser
// ele.parentNode.removeChild(ele)
// or
// document.body.removeChild(ele)
<body class='home'>
<nav class='test'></nav>
<div>Want to remove this elements</div>
</body>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With