2

I have the stylesheet:

#progress
{
    width:100px;
    height:8px;
    background-color:#CCCCCC;
    position:relative;
}
#progress:before
{
    content:"";
    position:absolute;
    left:0;
    background-color:#0066CC;
    width:50px;
    height:8px;
}

HTML content

<div id="progress">

I want to change the property width:50px of #progress:before by jquery

$('#progress:before').css('width',60);

but it doesn't work. can any one help me. I'm not good at English, thank you!

phibao37
  • 2,230
  • 4
  • 26
  • 35

2 Answers2

1

pseudo-elements themselves are not part of the DOM, and thus you can't select and manipulate them directly with jQuery (or any JavaScript APIs for that matter, not even the Selectors API). things you are doing are not possible :)

Ashisha Nautiyal
  • 1,389
  • 2
  • 19
  • 39
1

The pseudo selector modifies, not selects. The content created is purely presentational and is not injected into the DOM. Thus, you can't do what you'd like to do with jQuery.

For a more thorough answer, see How do I access style properties of pseudo-elements with jQuery?.

Community
  • 1
  • 1
Derek Henderson
  • 9,388
  • 4
  • 42
  • 71