Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selector, css path replace :eq

I have a problem with my JavaScript script.

I need to export a CSS style that I have set with a tool to a browser readable CSS file. A JavaScript function gets the path of the element that I change and returns something like this:

html>body>div:eq(2)>div>div:eq(1)>article>div>div>p:eq(1){text-decoration:underline;}

The path works great with as a jQuery selector, but not valid in CSS file.

I've tried to replace the :eq element by :nth-child but despite it's a valid CSS file, the style won't apply.

What am I doing wrong? How can i convert my :eq to something that css understand.

like image 743
Leze Avatar asked Aug 10 '26 19:08

Leze


1 Answers

You can pass second argument flag in RegExp for global search:

new RegExp(pattern[, flags])

Use:

var regExp = new RegExp('(:eq)','g');

Working Demo

like image 71
Milind Anantwar Avatar answered Aug 13 '26 10:08

Milind Anantwar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!