October 22, 2024
Chicago 12, Melborne City, USA
jQuery

How can I return a single button?


The following code sucessfully targets all elements with .btn class.

$(".btn").toggleClass("pressed");

Meanwhile, this returns the first element with .btn class.

$(".btn")[0];

But why $(".btn")[0].toggleClass("pressed"); doesn’t work and return ".toggleClass is not a function in console."?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video