Harshit Laddha
Harshit Laddha

Reputation: 2124

How do i create a regular expression that append all my style selectors with a id

I am creating something wherein i have to add some css and html content to a div with an id #resultContainer, now this css and html is input by the user in textboxes, and i am using jquery to retrieve their values and append them to the #resultContainer but the problem is i want to append the styles with the prefix #resultContainer

like i want to replace the string -

p {...
}
p i{...
}

to

#resultContainer p{...
}
#resultContainer p i{...
}

Is there a way to do this, either by using regular expressions or is there a way to apply any css rules i write to that #resultContainer only and not outside that....

Upvotes: 0

Views: 86

Answers (1)

gen_Eric
gen_Eric

Reputation: 227270

This is a quick regex that seems to work:

/(.+)(?={)/g

Try it like this:

yourCSS.replace(/(.+)(?={)/g, '#resultContainer $1');

Here's a simple demo: http://jsfiddle.net/6Rf53/

Upvotes: 2

Related Questions