Jquery combines the class selector, next, and Prev methods to hide adjacent nodes.

Source: Internet
Author: User

In the page effect, sometimes weProgramThe ID attribute cannot be added to the looping column, because there may be multiple identical IDs in the list, so the jquery ID selector is not available. In this case, we can use the class selector,

At the same time, we may also need to limit the operations on this node element to the current Div (or table ).Code:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = UTF-8"   />
< Title > Jquery Effect </ Title >
< Script SRC = "Http://common.cnblogs.com/script/jquery.js" Type = "Text/JavaScript" > </ Script >
< Script Type = "Text/JavaScript" >
// Expand Hidden Layer
$ (Document). Ready ( Function (){
$ ( " . Part " ). Click ( Function (){
VaR Hidep = $ ( This ). Next ();
If (Hidep.css ( ' Display ' ) =   ' None ' ){
Hidep. Show ();
$ ( This ). Hide ();
}
Else {
Hidep. Hide ();
$ ( This ). Show ();
}
});
$ ( " . All " ). Click ( Function (){
VaR Hidep = $ ( This ). Prev ();
If (Hidep.css ( ' Display ' ) =   ' None ' ){
Hidep. Show ();
$ ( This ). Hide ();
}
Else {
Hidep. Hide ();
$ ( This ). Show ();
}
});
});
</ Script >
</ Head >
< Body >
<! -- Div -->
< Div Class = 'Classa' >
< P Class = "Part" > Content 1 </ P >
< P Class = "All" Style = "Display: none" > Content 1, hahaha, I expanded it. Here is more content. </ P >
</ Div >
< Div Class = 'Classa' >
< P Class = "Part" > Content 2 </ P >
< P Class = "All" Style = "Display: none" > Content 2, hahaha, I expanded it. Here is more content. </ P >
</ Div >
< Div Class = 'Classa' >
< P Class = "Part" > Content 3 </ P >
< P Class = "All" Style = "Display: none" > Content 3, hahaha, I expanded it. Here is more content. </ P >
</ Div >
</ Body >
</ Html >

 

That is to say, I want to expand the hidden content in classa without affecting the content in other identical classa. In fact, the focus here isJquery next, PrevMethods can also be used in other scenarios.

 

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.