Emphasize a feature within a dynamic DIV

How can I highlight the span(class="tiny") element individually when its containing div is active or clicked?

I have attempted to highlight the tiny span element without success, as only the entire div was highlighted. Here's the code snippet I've tried:

$('.main-class').on('click', '.row-fluid', function() {
    $(this).parent().find('.tiny').css('background-color', '');
    $(this).css('background-color', '#00fff0');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div class="main-class">
    <div class="panel-body" style="border: 1px solid black;margin: 5px;">
        <div class="row-fluid">
            <a>
                <h1>One</h1>
            </a>
            <div class="col-md-1">
                <span>I am up</span><br>
                <span class="tiny">ID no -123395</span>

            </div>
            <div rel="tooltip" style="display: flex; justify-content: flex-end;">
                <div class="radio">
                    <label class="lead">
                        <input id="1" name="one" required="required" value="yes" type="radio">
                        Yes
                    </label>
                    <div class="radio">
                        <label class="lead">
                            <input id="1" name="one" required="required" value="No" type="radio">
                            No
                        </label>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <br>


    <div class="panel-body" style="border: 1px solid black;margin: 5px;">
        <div class="row-fluid">
            <a>
                <h1>Two</h1>
            </a>
            <div class="col-md-1">
                <span>I am up</span><br>
                <span class="tiny">ID no -123987</span>

            </div>
            <div rel="tooltip" style="display: flex; justify-content: flex-end;">
                <div class="radio">
                    <label class="lead">
                        <input id="1" name="one" tabindex="1" required="required" value="yes" type="radio">
                        Yes
                    </label>
                    <div class="radio">
                        <label class="lead">
                            <input id="1" name="one" tabindex="1" required="required" value="No" type="radio">
                            No
                        </label>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

I want to specifically highlight only the span class="tiny" values when any elements in class="panel-body" are activated.

Answer â„–1

 $('.main-class').on('click', '.row-fluid', function() {
            $(this).parent().find('.smaller').css('background-color', '');
            $(this).parent().find('.smaller').css('background-color', '#ff00ff');
 });

Answer â„–2

One way to achieve this effect is by using CSS:

  1. Create a class for highlighting elements
  2. When clicked, remove the highlight class from any element that has it and add it to the clicked element

Based on comments, the code should target the class .tiny instead of calling css directly on $(this).

If adding CSS directly is not an option (as initially mentioned), you can dynamically add a style element using JavaScript.

Here's an example implementation:

$('.main-class').on('click', '.row-fluid', function() {
    $(".highlight").removeClass("highlight");
    $(this).parent().find(".tiny").addClass("highlight");
});
.highlight {
  background-color: #00fff0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div class="main-class">
    <!-- Your HTML content here -->
</div>

To dynamically add the style rule using JavaScript:

$("<style>")
.text(".highlight { background-color: #00fff0; }")
.appendTo(document.head);
$('.main-class').on('click', '.row-fluid', function() {
    $(".highlight").removeClass("highlight");
    $(this).parent().find(".tiny").addClass("highlight");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div class="main-class">
    <!-- Your HTML content here -->
</div>

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

Grab a hold of the currently active controller in Angular

Is it possible to access a reference to the current instance of the controller from within its definition? My goal is to use `$compile` to create a modal and have it bound to the same controller that initiated its creation. Below is an example of what I w ...

Hide overflow for images with unique shapes

Here are the two image layers: https://i.sstatic.net/lUUQC.jpg One shows a hand holding a phone, and the other is a black hole. This is how you can achieve it using HTML markup: <div class="wrapper"> <img class="wrapper__image" src="path/to/ ...

Comparing form submission with a button click to pass data using Ajax - success in one method but failure in the other

I am facing an issue with two pieces of jquery code in my Flask application. While one works perfectly, the other is not functioning as expected. Both the form and a button trigger the same function through ajax calls. Currently, for troubleshooting purpos ...

The issue of Django/Python static files not loading is causing disruption

mysite/settings.py """ Configuration settings for the Django project called mysite. This file was generated by 'django-admin startproject' using Django 1.9.5. For more details about this file, visit https://docs.djangoproject.com/en/1.9/topics ...

Convert the date and time of "2018-03-31T05:37:57.000Z" to a

I need help converting the universal time 2018-03-31T05:37:57.000Z to a timestamp in the form of 1520919620673. Can someone please provide guidance on how I can achieve this conversion? ...

Use custom styles or CSS for the file input element: <input type="file">

Can CSS be used to achieve consistent styling for <input type="file"> in all browsers? ...

Tips for placing text on top of an image within a <p> element

I am grappling with a situation where I have a div containing text within <p> tags, and also an accompanying PNG image. My goal is to position the image to the left of the div so that it overlaps with the text. Despite my attempts at utilizing z-inde ...

What is the best way to enable the delete function exclusively for users who are logged in?

I am currently working on implementing a delete function in JavaScript that will remove a MySQL row if and only if it was created by the user who is currently logged in. This means that users cannot delete rows they did not create. Below is the progress I ...

Which Web Browsers Support Canvas and HTML5?

Currently working on a project that involves using the HTML5 Canvas element. I am curious about which major browsers (including specific versions) actually support the Canvas tag. I am not interested in hearing about IE. In this tutorial Drawing shapes - M ...

Is it possible to derive the language code without using the Common Locale Data Repository from a rough Unicode text

I am currently developing a dictionary application. One of the features I am working on involves identifying the language of a Unicode character when entered by a user. For example: 字 - would return ['zh', 'ja', 'ko'] ا٠...

Tips for merging arrays conditionally in JavaScript

Currently facing a dilemma without a clear solution, aiming to provide minimal context and focus solely on the problem at hand A worker logs their daily hours at work, stored in the "dayli_data" array. If the worker misses logging hours, it triggers the " ...

Having trouble with the dropdown onclick event not triggering when an item is selected in React?

I am having an issue where the onclick event handler is not being called when a dropdown item is selected. In my code, I am generating a dropdown inside a loop in the componentDidMount() lifecycle method. I am passing an event handler function named "show ...

Struggling with Selenium as I attempt to click multiple "Remove" buttons, constantly encountering the StaleElementReferenceException error

I am facing a challenge when trying to remove multiple elements on a webpage. My current approach involves locating all the "Remove" buttons and clicking them one by one. However, I keep encountering a 'StaleElementReferenceException' as I remove ...

Laravel 5.0 facing issues with AJAX requests

For my Laravel 5.0 project, I am utilizing Google API's for Google Oauth login. After successfully retrieving the email and id_token of the currently logged-in user, I aim to send this data to the SigninController to access our own API. The goal is to ...

In React, components will consistently render the initial code

I have a chat application that requires authentication and uses cookies. Here's what I've been attempting: class AppHeader extends React.Component { constructor(props) { super(props) } render() { if (cookies.get(' ...

Guide to dynamically displaying different URLs based on checkbox selection using Ajax

My goal is to dynamically change the view of a page based on which checkbox is checked. Additionally, I want to ensure that when one checkbox is selected, another becomes unchecked. <input class="searchType" type="checkbox"></input> <input ...

Jquery Modal with Jquery Integration for Seamless User Experience

Looking for a modal window that can accommodate additional content, specifically another jquery script. For clarification, I am in need of a content modal window where a jquery gallery with various images can be loaded inside. Any suggestions? ...

Troubleshooting a Vue.js formatting problem in Visual Studio 2019

Encountering an issue with VS2019 while attempting to format this code section. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="milestone.ascx.cs" Inherits="uc.dms.milestone" %> <section class="content-header"> <h1> ...

Transferring JSON data to a non-RESTful WCF service

I am looking to implement a JavaScript function that can send an object as JSON to a WCF service for saving. Here is the current JavaScript code: <script> $(document).ready(function(){ $("#submitButton").click(function() ...

When refreshing a JavaScript array of objects, it creates duplicate entries within the array

Currently, I am developing a chat application within a Vue project and experimenting with different features. A fully-featured chat app must have the ability to live-update "seen" states. This means that when one user views the last sent message, the othe ...