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.
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.
Share Improve this question edited Jul 16, 2017 at 18:28 ibrahim mahrir 31.7k5 gold badges49 silver badges77 bronze badges asked Jul 16, 2017 at 18:24 Amit mishraAmit mishra 4171 gold badge7 silver badges16 bronze badges3 Answers
Reset to default 6Use 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>
You can use the nextElementSibling
:
let el = document.querySelector('nav').nextElementSibling;
document.body.removeChild(el);
<body class='home'>
<nav class='test'>d</nav>
<div>Want to remove this elements</div>
</body>
You can hide it with CSS by selecting the adjacent sibling selector (+), and setting it's display property to none
:
.test + div {
display: none;
}
<body class='home'>
<nav class='test'>Nav</nav>
<div>Want to remove this elements</div>
</body>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744301228a4567510.html
评论列表(0条)