Finding the error related to Jquery's .siblings() function has been quite challenging for me

Hello, I need some help troubleshooting my jQuery code. I am attempting to create a hover effect where hovering over one text element will apply CSS to the other two elements. I'm not sure if the issue lies in the $(".yo") or the ('blur') part of the code. Any insight would be greatly appreciated.

After editing the jQuery, I noticed that the CSS remains applied even after mouseout. Any suggestions on how to fix this?

Updated jQuery:

$(".blur").mouseover(function(){
    $(this).siblings().addClass('blur textshadow');
}).mouseout(function(){
    $(this).siblings().removeClass('textshadow out');
}); 

HTML:

<div class="yo">
<div class="blur out" id="one"> hi </div>
<div class="blur out" id="two"> my </div>
<div class="blur out" id="three"> name </div>
</div>

CSS:

div.blur
{
    text-decoration: none;
    color: #339;
}

div.blur:hover, div.blur:focus
{
    text-decoration: underline;
    color: #933;
}

Answer №1

.blur represent children - access them using $(this).children().

<a class="yo">
    <a class="blur out" id="one"> hi </a>
    <a class="blur out" id="two"> my </a>
    <a class="blur out" id="three"> name </a>
</a>

However, it is not recommended to nest <a> tags. Perhaps a div tag would be more appropriate?


.blur are siblings - retrieve them by using $(this).siblings().

<a class="yo">whatever</a>
<a class="blur out" id="one"> hi </a>
<a class="blur out" id="two"> my </a>
<a class="blur out" id="three"> name </a>

Answer №2

Condense it down to the following -

$('.blur').hover(
    function(){
        $(this).siblings().addClass('out textshadow');
},  function() {
        $(this).siblings().removeClass('out textshadow');
});

Update your CSS like so -

.blur { 
    text-decoration: none; 
    color: #339; }  
div.blur:hover, div.blur:focus {
    text-decoration: underline; 
    color: #933; }  
.textshadow { 
    text-decoration: none; 
    color: rgba(0,0,0,0); 
    outline: 0 none; 
    -webkit-transition: 400ms ease 100ms; 
    -moz-transition: 400ms ease 100ms; 
    transition: 400ms ease 100ms; }  
.out {
    text-shadow: 0 0 4px #339;}

Check out a live demonstration here: http://jsfiddle.net/r2gQ3/

On a side note, consider using a different name for the blur class to avoid any confusion with the .blur() method.

Answer №3

It appears that there may be an issue with the siblings function in your code. By using the "yo" class as a selector and attempting to find its siblings, you may not get any results because it has no siblings! You should consider looking for its children instead, as all other links are likely children of "yo".

Without testing your code myself, it is difficult to identify any other potential problems. Additionally, having 3 links inside another link seems odd - perhaps they should be contained within a div element instead?

I hope this feedback proves helpful.

Best regards, Christen

Answer №4

Revise this

$(".yo").mousedown(function(){

into

$(".yo > span").mousedown(function(){

Example:

$(document).ready(function(){
    $(".yo > span").mousedown(function(){
        $(this).siblings().addClass('highlight');
    }).mouseup(function(){
        $(this).siblings().removeClass('highlight');
    }); 
});

Try it out: http://jsbin.com/ajokok/1/edit

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

Tips for activating an HTML input field using Javascript

I am currently using localStorage to store a string input by the user as a title, which will be saved for future visits. I would like to implement a button that allows the user to delete the displayed text (from localstorage) and enables the input field fo ...

What is the best way to incorporate two banners on the Magento homepage alongside my flexslider?

I recently made the switch from using a camera.js slider on my website to a Flexslider. The reason for this change was that I couldn't make the camera.js slider clickable, and I wanted to eliminate the 'Click here' button. However, now that ...

Extra white space is visible below the footer and above when resizing the window

I'm experiencing some white space above and below my footer, there seems to be a gap appearing. Can you please review the CSS code provided below? .footer { background-image: url("../images/footer_image.png"); background-repeat: no-repeat; background ...

How to increase the arrow size using CSS

I am currently trying to adjust the height of the step in my registration process, but the arrow size remains unchanged. I have included the code snippet below, which I obtained from another website. Can anyone provide guidance on how to set the step arrow ...

Is it possible to cancel a series of AJAX calls initiated by $.when in jQuery?

If I'm using jQuery, I know that I can cancel an individual asynchronous call by following this syntax: var xhr = $.ajax(...); xhr.abort(); But is there a way to cancel all AJAX calls started with $.when? var xhr = $.when(ajaxOne(), ajaxTwo(), ajax ...

Tips for structuring a JSON array of objects with the help of jQuery and Bootstrap

Currently, I am in the process of developing an online shopping application using Struts 2, MySQL, jQuery, JSP, Bootstrap, Gson, and Tomcat. In my Java entity, I have a class named Product, which is linked to a controller action that returns a JSON array ...

Using Angular 4 to retrieve a dynamic array from Firebase

I have a dilemma while creating reviews for the products in my shop. I am facing an issue with the button and click event that is supposed to save the review on the database. Later, when I try to read those reviews and calculate the rating for the product, ...

Unable to vertically align images in the carousel

Greetings! I am currently working on my website www.acigaiabeta.esy.es and I am facing an issue with aligning the images of the carousel to the center vertically. Despite trying various solutions, such as following tips from this resource, the images remai ...

Finding HTML tag with a particular attribute in Swift

Is there a way to extract specific attribute tags from an HTML link? Currently, I am using the following code to retrieve the page content using SwiftSoup: // Checking if MyLink is working guard let myURL = URL(string: MyLink) else { ...

What is the best way to empty textfields following an ajax query in jquery?

Here's the jQuery function I'm using to perform an AJAX query: $("#add").click(function() { val1 = $('#add_lang_level').val(); val = $('#add_lang').val(); listitem_html = '<li>'; listitem_html ...

Leveraging Jquery to retrieve multiple values for dynamic updating in HTML

As I ponder over this dilemma, a suitable title eludes me to encapsulate my query. Behold the code in question: $(document).ready(function() { setInterval(function(){ $.get('/battleship/update_game/{{info.gameid}}/{{user.username}}', ...

Stopping Angular.js $http requests within a bind() event

As stated in this GitHub issue Is it expected to work like this? el.bind('keyup', function() { var canceler = $q.defer(); $http.post('/api', data, {timeout: canceler.promise}).success(success); canceler.resolve(); } ...

Using CSS nth-child to create a two-column checkers layout

I have formulated a form on my website that divides into two columns by using floats. I am interested in creating a "checkered" effect for these columns. Can anyone guide me on how to utilize nth-child to achieve this design layout? For reference, please c ...

javascript the unseen element becomes visible upon page loading

my website has the following HTML snippet: function getURLParameters() { var parameters = {}; var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { parameters[key] = value; }); return param ...

Accessing additional information from a database through a session in order to present a user's data in a profile layout

I am having trouble showing a user's profile information after they log in. Currently, I can only display the user's email stored in the session. The following is my login script: if(isset($_POST['login'])){ $email = mysqli_real_ ...

Tips for maintaining video height consistency while adjusting its attributes

When you click on a button, the video's poster and src attributes change. However, after clicking, the video height briefly becomes 0, causing an unsightly effect on the entire page. How can this be avoided? Please note - lorem.mp4 and ipsum.mp4 hav ...

Tips for utilizing the fixed position within a flexbox design

I am working on a flexbox layout with two columns. The left column needs to be fixed, while the right column should be scrollable. Can you provide some guidance on how to achieve this? Here is the code snippet that I have been using: #parent { d ...

What's the best way to fix a div to the bottom left corner of the screen?

I have explored various solutions regarding this issue, but none of them seem to meet my specific requirements. What I am trying to achieve is the correct positioning of a div as depicted in the green area in the image. https://i.sstatic.net/O9OMi.png Th ...

Conditional formatting for form field styles

Is there a way in Angular to conditionally render a material style? For instance, I am looking to apply the following style only to my Password form field text, and only when both input boxes have content: .mat-form-field-appearance-outline .mat-form-fiel ...

Is there a way to manually change the field color upon approval in AngularJS?

Within my application that utilizes the MEAN stack, I am using AngularJS as the front-end technology. How can I manually change the color representation of a tolerance value to 159.06 in a table? Check out my Plunker for more details. Please refer to m ...