JavaScript How can I change the content of a span nested in a button? change content span jquery,change content span css,change content

I would not suggest you to directly access span using class, as many elements can have same class. You should use button id and then inside it you should use class to search element.

$('#btn1').click(function() {
  $('#nrOne').toggleClass('black');
  $("#our").toggleClass('blue');
  var text = $("#our > .push-me").text().trim() === "+"?"-": "+";
  $("#our > .push-me").text(text);
})
.black {
  background-color: #000;
}
.blue {
  color: #66cccc;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>

<div class="container-heading">
  
  <h4 id="our">Our Services
    <span class="push-me"> + </span>
  </h4>
  
  <p>Aliquam mauris metus, viverra ac faucibus vitae, pellentesque vitae.</p>
  
</div>

<button id="btn1">Button </button>
<!--container heading end-->
Answer:1

You can make it neater by using CSS and ::after. This links the content directly to the current state of the button, rather than just toggling the content and hoping it stays in sync, e.g. if some other code set the CSS class but did not update the content.

#our > span.push-me::after {
  content:' + ';
}

#our.blue > span.push-me::after {
  content:' - ';
}

Then no other changes are required, other than removing the initial + from the <span> HTML.

$('#btn1').click(function() {
  $('#nrOne').toggleClass('black');
  $("#our").toggleClass('blue');
})
.black {
  background-color: #000;
}
.blue {
  color: #66cccc;
}

#our > span.push-me::after {
  content:' + ';
}

#our.blue > span.push-me::after {
  content:' - ';
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>

<div class="container-heading">
  
  <h4 id="our">Our Services
    <span class="push-me"></span>
  </h4>
  
  <p>Aliquam mauris metus, viverra ac faucibus vitae, pellentesque vitae.</p>
  
</div>

<button id="btn1">Button </button>
<!--container heading end-->
Answer:2

Just set it with jquery

$(".push-me").text(" - ");
Answer:3

Add this script also : -->

$('.container-heading').click(function() 
{
    if ($(".push-me").text() == "-")
    {
          $('.push-me').text('+');
    }
    else
    {
          $('.push-me').text('-');
    }
});
Answer:4

Add click handler to .push-me.

$('.push-me').on('click', function() {
 var txt = $(this).text();
  $(this).text(txt.trim()  == '+' ? ' - ' : ' + ');
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-heading">
    <h4 id="our">Our Services<span class="push-me"> + </span></h4>
    <p>Aliquam mauris metus, viverra ac faucibus vitae, pellentesque vitae.</p>
</div> <!--container heading end-->
Answer:5

I came across a weird code which I didn't understood. It would be great if I get explanation. function forEach(array, action) { for (var i = 0; i < array.length; i++) { action(array[i]); }...

I came across a weird code which I didn't understood. It would be great if I get explanation. function forEach(array, action) { for (var i = 0; i < array.length; i++) { action(array[i]); }...

I am using Google Geocharts and following Google's documentation (https://developers.google.com/chart/interactive/docs/gallery/geochart?hl=en) to setup a chart like this: google.charts.load('current',...

I am using Google Geocharts and following Google's documentation (https://developers.google.com/chart/interactive/docs/gallery/geochart?hl=en) to setup a chart like this: google.charts.load('current',...

  1. google.visualization undefined
  2. google.visualization.datatable undefined
  3. google.visualization.arraytodatatable undefined
  4. typeerror google.visualization is undefined
  5. new google.visualization.datatable() undefined
  6. google.maps.visualization is undefined
  7. google charts google.visualization is undefined
  8. error google.visualization is undefined

I am using a site that allows its users an admin panel for which we can add HTML/CSS/Javascript/Jquery to the site after their DOM is loaded. Since i am a user i can not change what is being loaded ...

I am using a site that allows its users an admin panel for which we can add HTML/CSS/Javascript/Jquery to the site after their DOM is loaded. Since i am a user i can not change what is being loaded ...

  1. remove content page
  2. remove page content sharepoint 2013
  3. remove outdated content page
  4. remove outdated content page google
  5. remove outdated content page google images
  6. google remove content page
  7. remove update content page
  8. remove content facebook page
  9. remove content web page
  10. drupal remove content page
  11. sharepoint remove page content section
  12. genesis remove page content
  13. javascript remove page content
  14. squarespace remove page content
  15. sharepoint remove page content
  16. squarespace remove page content homepage
  17. remove page number from content page
  18. sharepoint 2013 remove page content section
  19. remove-page-content-share

Trying to format/parse the following date stamp from the server into the users local time zone using momentjs library. Added fiddle: http://jsfiddle.net/2hgyb490/ I've tried moment.utc(date) ...

Trying to format/parse the following date stamp from the server into the users local time zone using momentjs library. Added fiddle: http://jsfiddle.net/2hgyb490/ I've tried moment.utc(date) ...