0

Consider this example.

I have a div and before it I added some content using :before in css. Now I want to access content(which is "some text before div ") I have added using jquery.

How can I do that?

html:

<div>A div</div>

css:

div:before{
  content:"some text before div ";

}
user4913383
  • 171
  • 1
  • 1
  • 11

2 Answers2

0

$('a#change-text').click(function() {
  $("div:contains('A div')").toggleClass('v2');
});
a#change-text {
  color: #00f;
}
div:before {
  content: "some text before div ";
}
div.v2:before {
  content: "text was changed ";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>A div</div>
<a id="change-text">Change text</a>
Sidharth Gusain
  • 1,473
  • 1
  • 13
  • 20
Maju
  • 616
  • 4
  • 9
0

function init() {
    document.getElementById("foo")
            .addEventListener("click", 
     function() {
            document.styleSheets[0].deleteRule[0];
            document.styleSheets[0].addRule('div:before','content: "some other text?"');
     }, false);
}
document.addEventListener( "DOMContentLoaded", init, false );
div:before{
  content:"some text before div ";
}
<body>
<input id="foo" type="button">
<div>[<-- div -->]</div>
</body>
Tibrogargan
  • 4,508
  • 3
  • 19
  • 38