Question: JQUERY Showing Data I am trying to correct this code, this is what I need to do 1) Right now the code is selecting the
JQUERY Showing Data
I am trying to correct this code, this is what I need to do
1) Right now the code is selecting the 5 h2 elements, but I only need to access 3 of the h2 elements (only the ones with the question and answers to show and hide).
2) Right now the code I am having has fadeout effect, however I want to have a simple hide and show in JQUERY. I only want the answers to the question to be shown and hidden in a simple way
3) The idea is to use the toggleClass() method to add and remove the icon and to show and hide the information.
4) Also I dont want to use $("#loginDiv form").fadeToggle(1000);
* {
margin: 0;
padding: 0;
}
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 100%;
margin: 20px;
padding: 10px;
}
section {
padding: 15px 25px;
width: 650px;
margin-top: 20px;
margin-left: 25px;
}
h1 {
font-size: 150%;
}
h2 {
font-size: 120%;
padding: .25em 0 .25em 25px;
cursor: pointer;
}
/* classes to be used */
.plus {
background: url(plus.png) no-repeat left center;
}
.minus {
background: url(minus.png) no-repeat left center;
}
.close {
display: none;
}
.open {
display: block;
}
ul {
padding-left: 45px;
}
li {
padding-bottom: .25em;
}
p {
padding-bottom: .25em;
padding-left: 25px;
}
aside {
margin-top: 50px;
}
aside h2,
header h2 {
cursor: auto;
}
/* The divs are hidden and the plus sign is shown when the page loads by setting the classes using jQuery When we toggle
a class, the original class remains, but the new class will be applied due to the CSS cascading order of precedence */
jQuery FAQs
Frequently Asked Questions
What is jQuery?
jQuery is a library of the JavaScript functions that you're most likely to need as you develop web sites.
Why is jQuery becoming so popular?
Three reasons:
- It's free.
- It lets you get more done in less time.
- All of its functions are cross-browser compatible.
Which is harder to learn: jQuery or JavaScript?
For most functions, jQuery is significantly easier to learn and use than JavaScript. But remember that jQuery
is JavaScript.
Resources:
jQuery Website -
http://jquery.com
$(document).ready(function(){
$("#faqs h2").addClass("plus").next("div").fadeOut();
$("#faqs h2").click(function(){
$(this).next("div").fadeToggle();
if($(this).hasClass("plus"))
$(this).removeClass("plus").addClass("minus");
else
$(this).removeClass("minus").addClass("plus");
$("#loginDiv form").fadeToggle(1000);
});
});
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
