-3

I need this button :

<div class="myButton" id="clearBefore">Click Me</div>

To change the 'content' in the pseudo class ":before" to 'text'.

CSS

.ms-ChoiceField-input:before{    content:'Old content'; }

/*after button click content changes*/
.ms-ChoiceField-input:before{    content:'New Content'; }

HTML

<div class="checkboxHiddenSelectContainer" data-toggle="filterList" style="display: block;">
     <div class="ms-ChoiceField">
        <input class="ms-ChoiceField-input">
        <label class="ms-ChoiceField-field"">
           :before
           <span class="ms-Label">Function</span>
           :after
        </label>
     </div>
    </div>
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

2 Answers2

0

HTML:

   <div class="checkboxHiddenSelectContainer" data-toggle="filterList" style="display: block;">
     <div class="ms-ChoiceField">
        <input class="ms-ChoiceField-input">
        <label class="ms-ChoiceField-field"">
           :before
           <span class="ms-Label content1">Function</span>
           :after
        </label>
     </div>
    </div>

CSS:

.content1:before {
content:'Old content'; 
}

.content2:before {
content: 'New content';
}

JS:

$('#clearBefore').click(function() {
  $('.ms-Label').removeClass('content1').addClass('content2');
  // if wanna toggle content
  // $('.ms-Label').toggleClass('content1').toggleClass('content2');
})
Sri Kanth
  • 151
  • 8
-1

It seems you've used a pseudo class in your HTML, which should not have the effect of a pseudo class. You should use them in your CSS:

.ms-Label:before {
  content: "I am before";
}

As far as toggling goes, if I understood you correctly, you could do that by adding a class toggle to the label and changing the previous selector to .ms-Label.toggled:before

eavidan
  • 5,324
  • 1
  • 13
  • 16