freak007
freak007

Reputation: 88

Get all the content within <style> tag in a html file using jquery

I have a html file and some css written inside style tag. I have requirement to extract text inside this tag. eg:

<style>
    html,body {
        margin: 0px;
        width:100%;
    }
    .center-text {
        text-align: center;
    }
</style>

I need to extract values inside this tag in a string using jquery. I tried several posts but couldn't get any appropriate answer.

Upvotes: 0

Views: 1749

Answers (1)

Hasan Elsherbiny
Hasan Elsherbiny

Reputation: 628

have you tried this?

$("#YourDiv").html($("style").html())

this will get css code as string and put it into div if you need to save it to db you can send it via ajax to your server

Upvotes: 1

Related Questions