I am new to jquery and I am trying to change the value of button “on click”, the toggle is working fine but it is not changing the value of Button Hide and show text…
<button type="submit" class="btn btn-primary" id="toggleButton">Hide text <i class="icon-play icon-white"></i></button>
<div class="disclaimer">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
$('#toggleButton').click(function(){
$('.disclaimer').toggle();
if($('.disclaimer').is(':visible')){
$(this).val('Hide Text');
} else {
$(this).val('Show Text');
};
});
EDIT
This post has been reformatted by enclosing the code block in 3 backticks
```
on their own lines.
The value ‘attribute’ of the button element is used to return the value of the button and not the text that is displayed inside the button unlike an input button which uses the value attribute for both the value and the displayed button text.
If you are using the button as a toggle and not submitting data then just change the text otherwise if you are submitting the button data then I guess you should be changing the text and the value to match.