0

We have a functionalitiy that we want, like hide a element of html, but we want it to activate this functionality with two diferents buttons of the page.

It's correct to add a class to the buttons, for example "hideElement" with no css rules, and then in jquery make:

    $(".hideElement").click(function(){
         $("#elementToHide").hide(); 
    });

Or it is incorrect or inelegant to add a css class with no css rules to the code?

2
  • 1
    Yes, it's completely valid Commented Feb 21, 2014 at 7:32
  • 1
    If it's jQuery, it's valid (pun intended). Commented Feb 21, 2014 at 7:34

3 Answers 3

1

Those are HTML classes, not CSS class. There is no such thing as a CSS class.

Using an HTML class to mark an element as a member of a group of elements with something in common is fine and what classes are for.

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

Comments

0

Yes it is valid. But adding class to elements is good when you have more then one element with same functionality. so if it is not the case you can use id instead of class.

Comments

0

Yes, it's fine.

The purpose of classes in HTML/CSS is to identify elements. You are using them for that exact purpose, so it is a valid and expected thing to do.

Comments

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.