0

I want to change to text from a button that is dynamically created by JS. I know how to bind a click event on the button, but don't know how to change the text when the page is loaded.

The html code of the button (this is dynamically created by a wordpress plugin).

<a href="#" class="btn loadMoreBtn" id="loadMored">Load more</a>

jQuery code:

jQuery('#loadMored').text('Toon meer producten');
8
  • What kind of button is it? Does it use a <button> tag or a <input type="button"> tag? Commented May 3, 2019 at 7:20
  • Nope, that doesn't work. Also doesn't work when I paste this in the console screen. .text() works in the console screen but not when my website loads. Commented May 3, 2019 at 7:20
  • @alex it's an <a> tag Commented May 3, 2019 at 7:21
  • The button is at the bottom of the product list: axces.houston-1.hybridmedia.be/nl/product Commented May 3, 2019 at 7:22
  • 2
    Its better to wrap those functions in document.ready event listener Commented May 3, 2019 at 7:26

2 Answers 2

1

You just need to load script after elements are rendered. In document.ready for example or in the bottom of your HTML code.

Sign up to request clarification or add additional context in comments.

1 Comment

Will be better if you add a code snippet as an example.
0

Your button isn't actually a button but an anchor. To change the text inside it you would do $("#loadMored").html("Toon meer producten");.

2 Comments

Your answer is looking for a <loadMored> tag. The author's version is correct for updating the text.
You should use #loadMored. But anyways that is not the actual reason because the issue is with referencing before the load of the DOM

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.