-4

I would like to use this style if an if statement runs. However Jquery seems to get confused with the syntax and gives me a bunch of errors. Does anyone know how I can escape the errors so I can still use the styling?

The Jquery that is giving errors looks like this:

 $("#inject-toc-here > ol > li::before").css("content", "counters(item, ".") " "");

The normal css looks like this:

#inject-toc-here ol li::before {
            content: counters(item, ".") " ";
       }

The part that is giving errors is that second value for the css. The inverted commas by counters(item....)....

Thanks in advance :)

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Daniel Bailey
  • 939
  • 5
  • 15
  • 35
  • 1
    How should this _string_ ever work?! `"counters(item, ".") " ""` You need to escape your strings correctly. – eisbehr Jul 30 '18 at 08:57
  • What do you mean by that? – Daniel Bailey Jul 30 '18 at 08:58
  • 1
    Apart from that string quoting issue, this should not work to begin with, because you can not use jQuery to select pseudo elements in the first place, https://stackoverflow.com/questions/5041494/selecting-and-manipulating-css-pseudo-elements-such-as-before-and-after-usin – CBroe Jul 30 '18 at 08:58
  • 1
    well well, just put that second arguments with single quotes – Satyam Pathak Jul 30 '18 at 09:00
  • 2
    _“What do you mean by that?”_ - since by responding with that, you can rather only mean that you don’t know the basics of using text literals, quotes/delimiters and proper escaping in JS yet - please go find a tutorial on that one first. _“The normal css looks like this:”_ - and that’s where you should keep this to begin with - in your stylesheet. _“I would like to use this style if an if statement runs.”_ - then add a _class_ to the element via JS, so that your stylesheet rule can become applicable based on that class. – CBroe Jul 30 '18 at 09:05
  • @CBroe I remembered now. Thanks for your detailed response. – Daniel Bailey Jul 30 '18 at 09:08

1 Answers1

-2
$("#inject-toc-here > ol > li::before").css('content", "counters(item, ".") " "');

This got rid of the error of the quotation marks. The rest of the code I will fix. But changing to single quote fixed the errors I was getting.

Daniel Bailey
  • 939
  • 5
  • 15
  • 35
  • _“This got rid of the error”_ ... and also completely changed the meaning. Now you are passing only _one_ parameter to the `css` method, with the value `content", "counters(item, ".") " "`, whereas before you were passing two parameters. Absolu-totally not the same thing. – CBroe Jul 30 '18 at 09:08