``I am interested in changing the class of the initial child within a specific column in a row by toggling it

I have been attempting to toggle the class of the first child of a selected column within a row. Here is the HTML code snippet:

         <div class="container row each-expertise">
            <div class="col l4 m4 skill-1">
                <div class="circle">
                    <i class="material-icons">phonelink_setup</i>
                </div>
                <h5>Software Development</h5>
                <p class="lead sotenue">If you have a problem to solve or an incredible idea to digitally showcase, I can assist you in expressing it through a Web, Mobile, or Desktop application. </p>
                <br class="show-on-med">
            </div>
            <div class="col l4 m4 skill-2">
                <div class="circle">
                   <i class="material-icons">web</i> 
                </div>
                <h5>Web Design and Redesign</h5>
                <p class="lead sotenue">If you need people to be informed about what you do, having a website is crucial. You may also require a redesign if you desire more out of your existing site. </p>
            </div>
            <div class="col l4 m4 skill-3">
                <div class="circle">
                    <i class="material-icons">airplay</i>
                </div>
                <h5>I.T | Tech Evangelism</h5>
                <p class="lead sotenue">I enjoy inspiring, motivating, educating, and uniting developers and I.T professionals to exchange ideas, skills, solutions, and experiences. </p>
            </div>
        </div>

Additionally, here is the JavaScript code provided:

$(document).ready(function() {
    $myskill = $("#expertise .each-expertise .col");
    $myskill.hover(function(){
      $(this).toggleClass("white indigo-text text-darken-2");
      $(this).siblings().find('.circle').toggleClass('circle').toggleClass('circled');
    });

});

However, despite these efforts, the code does not appear to be functioning as intended.

Answer №1

Get rid of siblings, simply:

$(this).find('.circle').toggleClass('circle').toggleClass('circled');

Sibling() identifies all elements that are siblings of $(this) excluding the element itself. Therefore, in siblings, there are no .circle elements.

Additionally, you can use toggleClass to toggle multiple classes:

toggleClass('circle circled');

To summarize:

$(this).find('.circle').toggleClass('circle circled');

Since on hover the circle class is removed, it would be more efficient to do this:

$(this).find('.circle, .circled').toggleClass('circle circled');

Answer №2

See the Demo

Avoid using siblings() to select other elements with the .col class.

Make sure to target both .circle and .circled classes, or else the first-child with the class circled will be left out.

$(document).ready(function() {
    var $myskill = $("#expertise .each-expertise .col");
    $myskill.hover(function(){
      $(this).toggleClass("white indigo-text text-darken-2")
      $(this).find('.circle, .circled').toggleClass('circle circled');
    });

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create a dynamic HTML page using JavaScript

When I click on the following links: How can I create a new page using JavaScript? Create and dynamically append elements I'm looking to dynamically add HTML elements with JavaScript within a div, but I don't want my code to become overly comp ...

showing corresponding response codes for each error code

I'm attempting to set up error messages for different response codes - 200, 400, 404, 408, and 500, but I seem to be missing something in my implementation. I checked out this resource on handling jQuery AJAX errors with HTTP status codes jQuery AJAX ...

Safari not updating CSS ::after positioning

I'm encountering a CSS issue specifically in Safari. Whenever I change the text of an HTML element, the position of ::after does not update accordingly. $('#view').text("Shorter text"); // this does not refresh the position of the #view::af ...

What could be causing this ajax request to return a 400 error?

I'm encountering a persistent 400 error and can't seem to figure out why. I've tried multiple approaches, but the error persists when using the request through admin-ajax.php. JQUERY: function handle_ajax_request(){ if(is_page(1404)){ ?> ...

Is it a bug if we utilize AngularJS to retrieve data for <li><a href>?

Using AngularJs, I am able to retrieve data from a MySQL database for my navigation bar on an HTML5 page. However, there seems to be an issue with opening links in the sub menu. Below is a snippet of my code: <div id="header-wrapper" class="wrapper"> ...

tracking the number of new buttons pressed (HTML/Javascript)

As a novice in programming, I am currently tackling a task involving a table in otree that displays 256 unique buttons using Javascript. Each button reveals an icon when clicked, thanks to a straightforward function. Within this function, I have incorpora ...

Struggling with the grid layout in percentage and feeling perplexed

As I delve into the world of grid systems, I find myself grappling to comprehend it fully. The complexities can sometimes leave me feeling inadequate in my understanding. From what I gather, a 12-column grid system without any margins means that the 12th ...

Scheduled Events and revising the date navigation in the calendar

https://developer.mozilla.org/fy-NL/demos/detail/html5-calendar/launch Among the codes provided, which specific code enables the use of the browser's back/forward buttons to change the day? I'm having trouble figuring it out. Additionally, do y ...

What is the best way to set two search parameters in JQuery?

My goal is to locate the element that has the class attribute jive-wiki-body and then identify its h1, h2, and h3 child elements so that I can iterate over them. Currently, this is my attempt: $("#ivuFrm_page0ivu1").contents().find(".jive-wiki-body")[0] ...

Is it possible to embed a stringified JSON object into the query string or URL using asp.net-mvc?

Recently, I've been working with a controller action on my asp.net-mvc site where I have the following code: asp.net-mvc Controller Action: public ActionResult MyAction(PostParams myParams) { //perform tasks } The PostParams class is defined as ...

What issue is being encountered with this JavaScript generated by PHP?

PHP on the host generates JavaScript code that results in an error stating: missing ; before statement The generated JavaScript code looks like this: try{ obj = document.getElementById('subcat'); }catch(e){} try{ obj.innerHTML = ...

Stopping a D3 slider: When the slide comes to a

I have implemented a D3 range slider in JS and I am trying to trigger an event when the slider stops at specific pair of points. Currently, my code looks like this: d3.select('#slider4').call(d3.slider().axis(d3.svg.axis().ticks(6).tickFormat(fu ...

Using FEWER loops to create column classes on Twitter - What is their functionality?

Bootstrap utilizes various LESS mixins to create its column classes, along with other classes; .make-grid-columns() { // Common styles for all sizes of grid columns, widths 1-12 .col(@index) when (@index = 1) { // initial @item: ~".col-xs-@{index} ...

Tabindex issue arises due to a conflict between Alertify and Bootstrap 4 modal

When trying to call an Alertify Confirmation dialog within a running Bootstrap 4 Modal, I encountered an issue with the tab focus. It seems to be stuck in the last element and not working as expected. I suspect that this might have something to do with th ...

Multiple requests were made by Ajax

I am facing an issue with my ajax code where it is being called multiple times. Below is my php code: (While loop extracts results from a database. For brevity, I have included just the modal and dropdown menu sections.) $rezPet = mysqli_query($kon, "SEL ...

Querying with Codeigniter in Ajax Data table only returns a single row

When using codeigniter to create an ajax data-table, I pass the User ID as a condition to retrieve records from a product orders table. $this->datatables->select('orders.order_user_id,orders.order_date,orders.order_id,orders.order_confirmation_ ...

Avoiding AJAX requests from timing out

One of my tasks involves one of my websites having to communicate with the API of another website. I am considering implementing a "wait" popup to inform users while an AJAX call is being made to trigger server-side code that will in turn make the API cal ...

Impeccable method to safeguard element from external css interference

Currently, I am working on a script that will be utilized across various pages and I want to ensure that the elements it generates are not affected by the CSS styles of those pages. Some individuals suggest using CSS like this: body>*{min-height:200px; ...

Develop ContentService API in Google Apps Script to retrieve and deliver JSON data stored in Google Drive

Exploring the latest features unveiled at Google IO 2012 is still a work in progress. When it comes to GAS and ContentService, the ability to create an API to serve content (from Google Drive) is a key highlight. An illustrative example would involve: var ...

Displaying Table Headers on Page Breaks in Laravel PDF with Webkit Technology

Let me provide some context: I am utilizing Laravel to generate a view that is then converted to a PDF using barryvdh/laravel-snappy with the help of wkhtmltopdf, and everything is functioning as expected. However, I am encountering difficulties in stylin ...