Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Alex Fts's avatar

How to append two classes on a single onclick

I want to use .append function on 2 different classes but on a single onclick function

<script>
    jQuery(document).ready(function($){
$(window).one('click', function() {
$(".am-fs__main-content").append("<b>Hello World 1</b>");
$(".am-fs__payments-sentence").append("<b>Hello World  2</b>");
  });
});
</script>

But When I add Second Append It stop working !

0 likes
18 replies
Sinnbeck's avatar

What does "stop working" mean? Error in console? The code looks correct

Alex Fts's avatar

@Sinnbeck not working means the 2nd append doesn't work! I think so It is a step form and I am using the second append on the last step that's why it's not working.

Alex Fts's avatar

@Sinnbeck No it's only working on the first step on the last step, not even a single append is working.

Sinnbeck's avatar

@Alex Fts So the isnt clicking 2 classes, but why this one line does not work?

$(".am-fs__payments-sentence").append("<b>Hello World  2</b>");
Alex Fts's avatar

@Sinnbeck I think this line is on the last step therefore it's not picking his class, Is there any alternative way to do this?

Sinnbeck's avatar

@Alex Fts Sorry you lost me. If you move it to the top in that click method, it works or it still does not work?

MichalOravec's avatar

You don't have an element with the class am-fs__payments-sentence. That's it.

cib88's avatar

@alex fts Probably not the answer but should it not be $(window).on('click', function() { and not $(window).one('click', function() { you've got one not on

EDIT -- I've created a quick pen and it seems to work fine if I understand the question correctly so could be a HTML markup issue. https://codepen.io/craig_codes/pen/QWrLRox

Please or to participate in this conversation.