-1
<html>
    <head>
        <a href"dynamic link" data=[data-menu-xmlid="testing.testing"]>
    </head>
    <body>
        <div class="class 1">
    <body>
<html>

How can i select "div" and "a" at same time?

3 Answers3

3

CSS

div, a {
  
}

JS

document.querySelectorAll("div, a");

const select = document.querySelectorAll("div, a");
console.log(select);
<div class="first">
  <a class="test"></a>
</div>
m4n0
  • 27,411
  • 26
  • 71
  • 84
Ahmed
  • 71
  • 1
  • 8
0

You can select both div and a with

div,
a{..style goes here..}

But this will be applied to all the div and a tags in the page so you have to include a div element or a section.

    section{
    div,a{
        style here
    }
}

So it will be apllied to a specific section

0

YOU CAN SELECT 2 DIFFERENT HTML ELEMENTS by putting both elements in same selector seperated by a ,

div,a {
   background-color: yellow;
}  
  • 2
    You need to include a `,` in between for selecting them both. Right now it will select only the `a` element inside `div`. – m4n0 Jul 06 '21 at 05:30