After seeing Toggling button text in jquery this question, I tried to re create it in my situation but can't seem to have it work.
Here is a fiddle of what I've done: http://jsfiddle.net/V4u5X/
$('.SeeMore2').click(function(){
var $this = $(this);
$this.toggleClass('SeeMore');
if($this.hasClass('.SeeMore2')){
$this.text('See More');
} else {
$this.text('See Less');
}
});
It seems to only ever run the if statement once. What am I missing?
Answer: Use the jQuery prop() and html() Methods You can simply use the jQuery prop() method to change the text of the buttons built using the HTML <input> element, whereas to change the text of the buttons which are created using the <button> element you can use the html() method.
To set the title property on an element, use: $('#yourElementId'). prop('title', 'your new title');
To manually rename a new button:Click on the new button to select it (or Ctrl+Click, if a macro has been assigned to the button). Click in the Name Box, at the left of the Formula Bar. Type a new name, to replace the existing butto name. Press Enter, to complete the name change.
$('.SeeMore2').click(function(){
var $this = $(this);
$this.toggleClass('SeeMore2');
if($this.hasClass('SeeMore2')){
$this.text('See More');
} else {
$this.text('See Less');
}
});
This should do it. You have to make sure you toggle the correct class and take out the "." from the hasClass
http://jsfiddle.net/V4u5X/2/
try this, this javascript code to change text all time to click button.http://jsfiddle.net/V4u5X/2/
html code
<button class="SeeMore2">See More</button>
javascript
$('.SeeMore2').click(function(){
var $this = $(this);
$this.toggleClass('SeeMore2');
if($this.hasClass('SeeMore2')){
$this.text('See More');
} else {
$this.text('See Less');
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With