2

I've the input buttons without any class or id and have onclick attr on that something like this:

<input type="button" onclick="myfunc();" />

And there are other input type buttons too and want to style to the buttons which have onclick attribute.

So, here I can do like this:

input[onclick="myfunc();"]{color: red;}

But in the onclick there may be any function like myfunc(), thisfunc(), or anyfunc().

So how can I select those input buttons which have onclick attribute.

2 Answers 2

6

The value can be omitted:

input[onclick]{color: red;}

On an unrelated note, this seems like an interesting use case. I would probably use something like this, perhaps styling the border or something instead of the text, in order to highlight form elements (or any other elements) with event handler attributes, for "debugging" purposes.

Sign up to request clarification or add additional context in comments.

Comments

0
     $(function(){
        $("#mybutton").click(function(){
           $(this).css("color","red");
        });

     });

You can also JQuery for your solution. Add attribute id="myButton" to your input button.

1 Comment

He said that the buttons didn't have IDs, so likely not what he's looking for. Also, why use jQuery when CSS will do?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.