Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript pesudo element getComputedStyle return undefined

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #266348
    sobhan konari
    Participant

    hi guys
    why this code return undefined for me?


    var span = document.querySelector('span'); var result = window.getComputedStyle(span,':after').getPropertyValue('position'); document.write(result);
    span{
            margin:0 auto;
            font-size:40px;
            display: inline-block;
            position: relative;
        }
    span:after{
        position: absolute;
      content: "";
      border:1px solid #f30;
      left:0;
      top:55px;
      width:45px;
    }
    
    
    
    #266349
    Shikkediel
    Participant

    Working fine?

    codepen.io/JpbJRE

    #266354
    Shikkediel
    Participant

    Only cause I can think of without seeing a demo is that you’ve put the code in the head section without a document ready wrapping function. Which means the script is executed before the page has been read (and the element “exists”).

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.