I have a FAQ area on my page that has all of the questions in a list and when a user clicks on a title, a DIV with the answer will expand into view. However, I'm having trouble when it comes to closing the answer DIV layer. One of two things happen...
This one will simply open and close each DIV layer individually therefore multiple answers can be open at once. I want only one open, when a user either clicks the same title or another title, the currently open layer should collapse.
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".faq_answer").hide();
jQuery(".faq_heading").click( function() {
jQuery(this).next(".faq_answer").slideToggle(500);
});
});
</script>
This one will collapse whatever layer is currently open when another title is clicked (which is good). However, when the SAME title is clicked it closes it and then reopens it.
<script type="text/javascript">
jQuery(document).ready( function() {
jQuery(".faq_answer").hide();
jQuery(".faq_heading").click( function() {
jQuery(".faq_answer").hide(500);
jQuery(this).next(".faq_answer").slideToggle(500);
});
});
</script>
Inside your click handler, instead of this:
jQuery(".faq_answer").hide(500);
Try this:
jQuery(".faq_heading").not(this).next(".faq_answer").hide(500);
Related
I have two divs with the same name. The first one contains a link the user can click to get to a new page, and a dropdown-arrow to open up the next div which holds more anchor tags. It looks like this:
<div class="container-div">
<a class="link-1">Men</a>
<span class="dropdown-arrow"></span>
</div>
<div class="container-div">
<a class="link-2">Featured</a>
<a class="link-2">Sale</a>
</div>
As it works now, when the user clicks the span.dropdown-arrow, the second container div opens revealing the .link-2 links. When the user clicks the Men link (a.link-1), it also opens up the second container div and also takes the user to a new page. I would like it so that when the user clicks ".link-1", the second container div does not open (remains as display:none).
Here is my jQuery:
function mobileMainNav(){
$('a.link-1').click(function(){
window.location = $(this).attr('href');
});
$('a.link-1').click(function(){
var showNone = $(this).parent().next('div.container-div').css('display', 'none');
console.log(showNone);
});
};
The first part of this function works, taking the user to the new window. But the second part does not work at all, and nothing is logged in the console either. What am I doing wrong?
So call stopImmediatePropagation but it is only going to work if the events are attached in the correct order.
$("button").on("click", function (e) {
console.log(1);
e.stopImmediatePropagation()
});
$("button").on("click", function (e) {
console.log(2);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>a</button>
I have multiple divs of the same class which act as notification boxes, and each one fades in one after the other, one by one using jQuery. I also have a div called 'close_box' which acts as a close button so when a user clicks this the div will close/hide using jQuery. The problem I am having is, because the divs have the same class, when a user clicks the 'close_box' div this should close each div separately. Instead whats happening is all three divs are suppose to have a close button showing 'close_box' div, but only the third box is showing this and only the third box is closing while the other two boxes are not showing the 'close_box' div and can't be closed.
Is there a way I can use parent or some similar idea to close each div separately and can someone please show me where I am going wrong and how to do this? thanks
<div class="noti_box"><div class="noti_text"><h4>You have 11 New Messages</h4></div><div class="close_box"></div></div>
<div class="noti_box"><div class="noti_text"><h4>You have 11 New Notifications</h4></div><div class="close_box"></div></div>
<div class="noti_box"><div class="noti_text"><h4>6 Matters Needing Your Attention</h4></div><div class="close_box"></div></div>
<script type="text/javascript">
$('.noti_box').each(function(i) {
$(this).hide().delay(i * 1500).fadeIn(1500);
$('.close_box').on('click', function() {
$(this).closest('.noti_box').fadeOut();
}).appendTo(this);
});
</script>
Just separate these two actions and remove appendTo(this):
$('.noti_box').each(function(i) {
$(this).hide().delay(i * 1500).fadeIn(1500);
});
$('.close_box').on('click', function() {
$(this).closest('.noti_box').fadeOut();
});
What you posted is just the wrong interpretation of my example from your previous question.
DEMO: http://jsfiddle.net/F39TV/4/
I am using jQuery CustomBox modal. I have it all working fine but I want the div behind it (BUT NOT THE BACKGROUND IMAGE) to disappear when modal is clicked. I have managed that, but not too sure on the code to make it reappear again after the modal is closed. At the moment I have to refresh the page in order for it to come back.
Here is the code I am using so far: http://codepen.io/doolz77/pen/esoHB/
I have not included the modal due to the amount of extra code, however, here is a link to the actual page
to make the modal appear just click on the 'joey' link.
Thanks!
EDIT: At the moment it is controlled by jQuery. The call which is placed in the footer is:
<script>
$(function () {
$('#fadein').on('click', function () {
$.fn.custombox( this {
effect: 'fadein'
});
return false;
});
});
</script>
This fades the modal in and out. Would I just need to place some code here for the #wholePageContainer div to re-appear??
You need to store the html before deleting it to retrieve later. Or you can use show/hide To reduce the pain and achieve desired functionality:
function clearBox(wholePageContainer)
{
document.getElementById(wholePageContainer).style.display = "none";
}
function showbox(wholePageContainer)
{
document.getElementById(wholePageContainer).style.display = "block";
}
Demo
Is this what you were looking for:
http://codepen.io/anon/pen/giFEL
Edited:
Explanation to the above link:
In the above link i have made the html and body tag as 100% and the div element who's content is been removed to some percentage i.e 50%, This will keep the div occupy space event if it is empty.
Next i am storing the html content to a hidden div element and restoring it back to the div when required.
I have several pop-ups on home page. I open and close them by selecting them with ID and using fadeIn() and fadeOut(). Now I want to open a specific pop-up by clicking on link from another window? For example, if from that new window I click on 'Pop Up 1', I want home page to open and then show 'Pop Up 1'.
I tried using this code below but while writing this code I realized that the script gets reloaded and thus my function of loading a pop-up does not work.
So my question is, is there some elegant solution you could recommend to show element in one page while a link that specifies which element has to be shown is in another?
$("#galleryNav a").on('click', function() {
window.open("/pixeleyes",'_self',false);
setTimeout(function() {
var popToShow = $(this).attr('data-pop');
$(".text-content-outer").hide();
$("#" + popToShow).fadeIn();
}, 5000);
});
One idea might work is
When you are opening a new page using the below line then send some parameter or hash value with it.
window.open("/pixeleyes",'_self',false);
like
window.open("/pixeleyes#openpopup",'_self',false);
Then in the page ready of this page check if the hash exists open the popup otherwise do nothing.
Not sure if this is what you are looking for.
$("#galleryNav a").on('click', function() {
window.open("/pixeleyes#showpopup",'_self',false);
});
showpopup could be anything that you want to open as popup...
Trying to get a button working in the titlebar is becoming a little difficult. At present the button opens when clicked (calls a window with a webview), and closes when an html button is clicked. But only once. The issue is that after the window is closed, the titlebar button seemingly wont reopen the window...
This is probably a simple error, but one i'm having difficulty finding an answer to.
My app.js:
var infoBtn = Titanium.UI.createButton({
title:'Info'
});
// ABOUT
var win0 = Titanium.UI.createWindow();
var webview0 = Titanium.UI.createWebView({url: 'about.html'});
infoBtn.addEventListener('click', function() { win0.open(); });
Ti.App.addEventListener('closeAbout', function() { win0.close(); });
win0.add(webview0);
win0.hideNavBar();
My about.html:
<head>
<script type="text/javascript" charset="utf-8">
function closeAboutBtn() {
Ti.App.fireEvent('closeAbout');
}
</script>
</head>
<body>
Return to App
</body>
Would anyone have any ideas on how to fix so the about button shows the content when pressed every time?
First quick response would to be just "hide" the window instead of closing it.
verified:
The only way I was able to consistently get he window to hide and show is as follows
// listener assigned to info button
infoBtn.addEventListener('click', function() {
Ti.API.log('info button clicked, show window');
win2.open();
win2.show();
});
// Listener assigned to close in about window
Ti.App.addEventListener('closeAbout', function(data) {
Ti.API.log('info button clicked, close window');
win2.close();
win2.hide();
});