JavaScript Link text changes on click. See more, See less jquery - Bootstrap accordion

So I've used bootstrap accordion to hide/unhide info.

I needed the wording to change from 'See more' to 'See less' continuously.

I've implemented this as you can see in the bootply

As you will see, the problem I'm facing is that when first clicked it moves from 'See more' to 'See more' then click again it starts working as I want it to.

I know why its happening but cant figure out how I can remove the a href text and show the hidden info straight away.

$(document).ready(function () {
    $("#morebtn").click(function () {
        $(this).html($(this).html() == "See more" ? "See less" : "See more");
    });
});
Answer:1

It's because first time round your HTML is actually <strong>See more</strong> not "See more" as you think.
Change it to $(this).text() == "See more" and it works :)
You can then just add a class to the element to make it bold. Otherwise you'll need to re-wrap with the <strong> tag each time

Answer:2

remove the tag around your See more text and apply that style via css, it will work.

Answer:3

Try This

 $(this).html(($(this).html() == "See more" )? "See less" : "See more");

tested worked for me

ensure that id is given to dom element which support html() property

i tried with

  <div id="morebtn"  style="background-color:red;width:64px;height:56px;"></div> 

if id given to button then use

    $(this).attr('value',($(this).attr('value') == "See more" )? "See less" : "See more");
Answer:4

I'm using the following code to detect multiple keys on a keypress event: var down = []; $(document).keydown(function (e) { down[e.keyCode] = true; }).keyup(function (e) { if (down[17] &...

I'm using the following code to detect multiple keys on a keypress event: var down = []; $(document).keydown(function (e) { down[e.keyCode] = true; }).keyup(function (e) { if (down[17] &...

  1. prevent spaces input
  2. prevent spaces in input field
  3. prevent spaces in input field angular
  4. prevent spaces in input field html
  5. javascript prevent spaces in input
  6. angular prevent spaces in input
  7. jquery prevent space input

I need to chagen my JSON output which is: [ { masterCardNo: 90363.01 }, { masterCardNo: 90363.02 }, { masterCardNo: 90363004 }, { masterCardNo: 90363004 }, { ...

I need to chagen my JSON output which is: [ { masterCardNo: 90363.01 }, { masterCardNo: 90363.02 }, { masterCardNo: 90363004 }, { masterCardNo: 90363004 }, { ...

I'm trying to achieve the below result by ONLY using the "labels" class (eg. I don't want the "arrow" class/html). Is this possible with pseudo elements only? Like ".labels:tesing{}" etc. .labels{ ...

I'm trying to achieve the below result by ONLY using the "labels" class (eg. I don't want the "arrow" class/html). Is this possible with pseudo elements only? Like ".labels:tesing{}" etc. .labels{ ...

The problem is the same as in Close all HTML unclosed IMG tags, but the provided regexp (<img[^>]+)(?<!/)> requires lookbehind support - which nodejs does not have. How can I achieve the ...

The problem is the same as in Close all HTML unclosed IMG tags, but the provided regexp (<img[^>]+)(?<!/)> requires lookbehind support - which nodejs does not have. How can I achieve the ...