• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

99
Views
.get() method failing in Jquery

I am trying to access and style the different objects inside a jQuery object by using .get(); and I have been successful in simply accessing the individual objects but unable to perform operations like adding css or classes to those individual elements. I also tried to use [] to access and style; but access is again a success while I am not being able to style that selected element. Why is this happening?

my script using .get() =>

$(()=>{
  $('button').click(function(event){
    $(".box div").get(1).toggleClass('color');
  });
});
.box{
  font-size: 0px;
  width: min-content;
}

.color{
  display: inline-block;
  width: 20px;
  height: 20px;
  background-color: red;
  border: 1px solid white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="box">
  <div></div>
  <div></div>
  <div></div>
</div>

<button>click</button>

TypeError: $(...).get(...).toggleClass is not a function

Why is this message coming? How to resolve this and get specific index element from a jQuery Object?

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

i hope this helps you.

$(()=>{
  $('button').click(function(event){
    $(".box div:nth-child(1)").toggleClass('color');
  });
});
.box{
  font-size: 0px;
  width: min-content;
}

.color{
  display: inline-block;
  width: 20px;
  height: 20px;
  background-color: red;
  border: 1px solid white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="box">
  <div></div>
  <div></div>
  <div></div>
</div>

<button>click</button>

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error