search

Home  >  Q&A  >  body text

What is the purpose of a reference inside a div tag without attributes?

I want to start using attribute selectors in my css. I see that the div tag contains references but does not have any attribute statements, for example:

<div class="container" data-footer>

All my searches (for the past hour) have turned up no information on how to list "data-footer" without using attribute= (e.g. id= or class= etc.). Dozens of SO and Google links without a single reference example inside a div tag without using attributes. Since I don't know what this is (or what to call it), I may not be using the correct keywords for my search. Is this a short way of passing the id or???

P粉197639753P粉197639753253 days ago346

reply all(1)I'll reply

  • P粉520545753

    P粉5205457532024-03-21 00:05:36

    Data attributes without a value can be used as Boolean values. For example:

    if(div.hasAttribute('data-footer')) {
       // then do something
    }

    In css you can access it like this:

    div[data-footer] {
    
    }

    reply
    0
  • Cancelreply