Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set an onChange event using CSS?

I want to have all input elements on my page trigger a function when they change. Can I do it from a CSS?

I tried this:

<STYLE type="text/css">
   input {onChange: function() {alert("foo");};}
</STYLE>

It didn't work in Google Chrome.

like image 722
Eyal Avatar asked Dec 06 '25 07:12

Eyal


1 Answers

CSS doesn't provide eventing. If this is what you want, then I would write a JavaScript function that runs when the page loads. In the function, traverse the form elements for everything that has the tagName input. For each of those, add an event handler.

like image 56
Gabriel McAdams Avatar answered Dec 07 '25 20:12

Gabriel McAdams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!