JQuery's hover method works with css's hover selector to highlight selected elements. jqueryhover

Source: Internet
Author: User

JQuery's hover method works with css's hover selector to highlight selected elements. jqueryhover
Problem description:

Today, I met the following requirement to help my sister develop a webpage:

Do not move the mouse to the table. The transparency of the table remains unchanged.

Move the cursor to the table, and the transparency of the hover to cells remains unchanged.

Paste the results I have achieved. At first, the table transparency remains unchanged.

 

When I move the cursor to the third cell in the second row, other cells decrease the transparency.

 

Solution

At first, I used the CSS implementation method, as shown below:

#table td{    opacity:0.5;}#table td:hover{    opacity:1;}

However, at the beginning, the table transparency is 0.5, which looks bad.

Later, I used the hover method of jQuery, but it always selects all the cells in it. The process is tortuous and I will not introduce them one by one. I will explain how to implement it.

$('#content td').hover(        function(){            $('#content td').css('opacity','0.5');            $('#content td:hover').css('opacity','1');            },        function(){            $('#content td').css('opacity','1');        });    

Content is the id of my table. We can see that two functions are added to the cell hover method.

When the first funtion is moved to the table

$('#content td').css('opacity','1');

Indicates that when the mouse moves in, the transparency of all cells is 0.5, and then

$('#content td:hover').css('opacity','1');

The hover selector of css indicates selecting a single cell.

The second funtion indicates that when the mouse leaves the table

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.