Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert script via CSS content property

Tags:

css

tags

Is it possible to insert script tag using content property of CSS?

The example below inserts plain text instead of a html tag

#someDiv:before {
    content:"<script>$(function(){ console.log('test');});</script>";
}
like image 342
Az. Avatar asked Mar 24 '23 07:03

Az.


1 Answers

Content inserted with the content property will only ever be plain text. This is to prevent recursion. It also helps by preventing people from doing crazy things like inserting script elements with CSS.

like image 51
lonesomeday Avatar answered Apr 07 '23 14:04

lonesomeday