-4

I'm trying to select one class that is created dynamically, or another class that is created in html. What would be a good way of doing this?

I've tried this:

$('.wrapper' || '.surround').on('click', '.bet-button', function(){}

and also this:

$('.wrapper', '.surround').on('click', '.bet-button', function(){}

is there a way to write this, so far it doesn't seem to be working.

Bkes
  • 137
  • 8

2 Answers2

3

You're almost there:

Only separate them with comma

$('.wrapper, .surround').on('click', '.bet-button', function(){}
Ele
  • 33,468
  • 7
  • 37
  • 75
  • Can you explain how that make sense, why would I wan the comma to be inside of the quotations? Thanks for the help though! – Bkes Mar 28 '18 at 20:38
  • @Bkes because that's how selectors work. It's the same as in CSS. If you put the comma inside the String, you're passing it to jQuery. Otherwise, you're calling `$(a, b)` which evaluates to `$(b)` (Javascript comma operator) –  Mar 28 '18 at 20:39
  • Ah ok, thank you! Had a moment there haha – Bkes Mar 28 '18 at 20:42
  • @Bkes Chris has already explained `:)` – Ele Mar 28 '18 at 20:42
1

Can you try

$('.wrapper, .surround').on('click', '.bet-button', function(){}
abbas-ak
  • 642
  • 3
  • 13