Last Updated: February 25, 2016
·
2.025K
· xero

css style injection via jQuery

basically calling body/head append with a style tag and your own css will add a new tag and your styles to the bottom of the page/head and override any existing ones. why is this useful? imagine embedding a single js file into the page and defining your own styles (think widget for a client), or loading css via ajax, etc.

$('head').append('<style type="text/css">.myCSS{color:#00ff00}</style>');

here's an example gist :: http://git.io/V3q1MQ

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside