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.
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.
Share Improve this question edited Jun 16, 2022 at 12:28 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Oct 14, 2010 at 15:55 EyalEyal 5,8487 gold badges48 silver badges76 bronze badges 2- What does CSS have to do with JavaScript and DOM events? – Nikita Rybak Commented Oct 14, 2010 at 15:57
- to me, thats blasphemy! CSS is for styles my friend, not logic. – Rajat Commented Oct 14, 2010 at 21:09
3 Answers
Reset to default 5CSS 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.
No you can't that is against the very nature of CSS. The only thing close are Pseudo-Classes like :focus :hover ect, but even they only allow to apply a different Style. So no, you can't just write JS in a CSS File and call it CSS :)
No you can't. About the error in google chrome, use onblur. refer to the following post for more info:
http://www.google./support/forum/p/Chrome/thread?tid=5480bd096a668f1e&hl=en