Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js dom after selectors

//set an attribute and get it in js and set value
p:before {
    content: attr(data-before);
    color: red;
    cursor: pointer;
}

$('p').on('click', function () {
    $(this).attr('data-before','bar');
});
// or

//Add/remove a predetermined class

p:before {
    content: "foo";
}
p.special:before {
    content: "bar";
}


//or 

var str = "bar";
document.styleSheets[0].addRule('p.special:before','content: "'+str+'";');

//read ::after,::before

var str = window.getComputedStyle(document.querySelector('p'), ':before') 
           .getPropertyValue('content');
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #dom #selectors
ADD COMMENT
Topic
Name
5+7 =