OiO.lk Blog jQuery How can I return a single button?
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

Exit mobile version