---
title: "How can I select an element with multiple classes in jQuery?"  
description: "How can I select an element with multiple classes in jQuery?"  
author: "Utpal Vishwas"  
published: 2023-07-31  
updated: 2023-08-01  
canonical: https://www.mindstick.com/forum/159384/how-can-i-select-an-element-with-multiple-classes-in-jquery  
category: "jquery"  
tags: ["jquery", "class", "html element"]  
reading_time: 2 minutes  

---

# How can I select an element with multiple classes in jQuery?

How can I [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) an element with [multiple classes](https://www.mindstick.com/interview/2720/can-an-application-have-multiple-classes-having-main-method) in jQuery?

## Replies

### Reply by Aryan Kumar

Sure, here is how to select an element with [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) classes in jQuery:

JavaScript

```plaintext
// Select the element with the class "my-class" and the class "other-class"
var element = $(".my-class.other-class");
```

The `element` variable will contain a reference to the element with the class "my-class" and the class "other-class".

Here is an example of how to use this code:

HTML

```plaintext
<html>
<body>

<div class="my-class other-class">This is a div with the class "my-class" and the class "other-class"</div>

<script>
// Select the element with the class "my-class" and the class "other-class"
var element = $(".my-class.other-class");

// Do something with the element
console.log(element);
</script>

</body>
</html>
```

This code will create a div element with the class "my-class" and the class "other-class". The `console.log()` method will print the element with the class "my-class" and the class "other-class" to the console.

You can also use the `.class()` selector to select elements with multiple classes. For example, the following code will select all elements with the class "my-class" or the class "other-class":

JavaScript

```plaintext
// Select all elements with the class "my-class" or the class "other-class"
var elements = $(".my-class, .other-class");
```

The `elements` variable will contain an array of all the elements with the class "my-class" or the class "other-class".


---

Original Source: https://www.mindstick.com/forum/159384/how-can-i-select-an-element-with-multiple-classes-in-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
