how to select :after element using jquery

前端 未结 4 1161
名媛妹妹
名媛妹妹 2020-12-16 15:25

Bellow is my codes.what i have tried.when this popup appear i want to use this close button to close entire popbox.

CSS code

.bigdiv{
    display:non         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 16:03

    I want to select :after elements .how to do that using jquery ?

    You can't, generated pseudo-elements don't exist in the DOM (yet, sadly).

    We can prove this like so:

    CSS:

    #foo:before {
      content: '[Before]'
    }
    #foo:after {
      content: '[After]'
    }
    

    HTML:

    Foo

    JavaScript:

    (function() {
    
      var msgs = [];
      var child;
      var div;
    
      for (child = document.body.firstChild;
           child;
           child = child.nextSibling) {
        if (child.id) {
          msgs.push("Child " + child.nodeName + "#" + child.id);
        }
        else {
          msgs.push("Child " + child.nodeName);
        }
      }
    
      div = document.createElement('div');
      div.innerHTML = msgs.join("
    "); document.body.appendChild(div); })();

    The page resulting from the above (if we assume the script element is added to body at the end) is:

    [Before]Foo[After]
    Child DIV#foo
    Child SCRIPT

    Live Copy | Source

    As you can see, the generated pseudo-elements are just not present at all as far as the DOM is concerned.

提交回复
热议问题