admin管理员组文章数量:1392007
This code is listed on the header of all of my webpages. When I click a link on my website, I'm unable to use the buttons on the page until after I refresh. How can I fix this?
<script src=".1.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.faqElement').click(function() {
var faqElement = $(this);
var question = faqElement.find('.faqQuestion');
var answer = faqElement.find('.faqAnswer');
if (!answer.hasClass('activeFaqAnswer')) {
$('.faqElement').removeClass('flipButton');
faqElement.addClass('flipButton');
$('.activeFaqAnswer').css('max-height', '');
$('.faqAnswer').removeClass('activeFaqAnswer');
answer.css('max-height', 'none');
answer.css('max-height', answer.height());
answer.addClass('activeFaqAnswer');
}
});
});
</script>
This code is listed on the header of all of my webpages. When I click a link on my website, I'm unable to use the buttons on the page until after I refresh. How can I fix this?
<script src="https://code.jquery./jquery-2.1.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.faqElement').click(function() {
var faqElement = $(this);
var question = faqElement.find('.faqQuestion');
var answer = faqElement.find('.faqAnswer');
if (!answer.hasClass('activeFaqAnswer')) {
$('.faqElement').removeClass('flipButton');
faqElement.addClass('flipButton');
$('.activeFaqAnswer').css('max-height', '');
$('.faqAnswer').removeClass('activeFaqAnswer');
answer.css('max-height', 'none');
answer.css('max-height', answer.height());
answer.addClass('activeFaqAnswer');
}
});
});
</script>
Share
Improve this question
edited Mar 5, 2017 at 1:09
Mohamed-Yousef
24k3 gold badges21 silver badges28 bronze badges
asked Mar 5, 2017 at 0:48
HazzyqHazzyq
311 silver badge2 bronze badges
2
- 2 Can you share some more code? What buttons are you referring to? What classes are present on the buttons? Are there any javascript errors logged in the console? – san Commented Mar 5, 2017 at 0:51
- What happens if you were to put this at the end of your code (not just the end of header)? – Jason Fel Commented Aug 16, 2017 at 12:55
2 Answers
Reset to default 3This sounds like a conflict with your custom script and Squarespace's AJAX loading:
Occasionally, Ajax may conflict with embedded custom code or anchor links. Ajax can also interfere with site analytics, logging hits on the first page only.
So, depending on your template, you may find that disabling AJAX is a simple solution:
You can disable Ajax in the Style Editor, with some exceptions:
- Ajax can't be disabled in Skye, Foundry, or Tudor.
- Ajax can't be disabled on the blog landing page for Farro and Haute. If you uncheck Enable Ajax Loading in these templates, they will still use Ajax to load the Blog Page.
To enable or disable Ajax:
- In the Home Menu, click Design, and then click Style Editor.
- Scroll down to Site: Loading.
- Check or uncheck Enable Ajax Loading.
If you do not want to disable AJAX altogether, then see "Option 2" in this answer for ways to write your code so that it will work on initial page load and on AJAX page loads.
It seems Ajax loads content dynamically and ruins your bindings.
You could call your function after each Ajax request using $.ajaxComplete()
<script src="https://cdnjs.cloudflare./ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script>
function faqElementClick() {
$('.faqElement').click(function() {
var faqElement = $(this);
var question = faqElement.find('.faqQuestion');
var answer = faqElement.find('.faqAnswer');
if (!answer.hasClass('activeFaqAnswer')) {
$('.faqElement').removeClass('flipButton');
faqElement.addClass('flipButton');
$('.activeFaqAnswer').css('max-height', '');
$('.faqAnswer').removeClass('activeFaqAnswer');
answer.css('max-height', 'none');
answer.css('max-height', answer.height());
answer.addClass('activeFaqAnswer');
}
});
};
$(document).ready(faqElementClick);
$(document).ajaxComplete(faqElementClick);
</script>
本文标签: JavascriptJQuery not working until after page reloadStack Overflow
版权声明:本文标题:JavascriptJQuery not working until after page reload - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744774029a2624515.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论