jquery click function addclass











up vote
0
down vote

favorite












I've got a strange problem where "most" of my rules work inside a click function, but one won't



$(".fadeOut input").click(function() {
$(".nooverlay").addClass("overlayon");
$(".searchBar").addClass("fadeIn");
$(".searchBar").removeClass("fadeOut")
});


addClass("overlayon") won't work ?!?!?

fadeIn works

fadeOut works



the entire js can be seen here:
https://github.com/TerminalAddict/ta.com-website/blob/master/assets/js/ta.js



I'm using to yui-compressor to compress, then create one big bundle (bundle.js)



no errors in console, and if I paste this function into the console it works fine.



Live demo: https://terminaladdict.com










share|improve this question







New contributor




TerminalAddict is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • I've also tried: $("fadeOut").on("click", "input", function(a) { a.preventDefault(); $(".nooverlay").addClass("overlayon"); $(".searchBar").addClass("fadeIn"); $(".searchBar").removeClass("fadeOut") });
    – TerminalAddict
    Nov 5 at 2:49












  • What's the purpose of the classes nooverlay and overlayon?
    – D. Smania
    Nov 5 at 3:05










  • overlayon to create a 100% height 100% width overlay with with opaque background, that is clickable (to close the searchbar) nooverlay, because I though jquery was getting confused by not having an original class
    – TerminalAddict
    Nov 5 at 3:20















up vote
0
down vote

favorite












I've got a strange problem where "most" of my rules work inside a click function, but one won't



$(".fadeOut input").click(function() {
$(".nooverlay").addClass("overlayon");
$(".searchBar").addClass("fadeIn");
$(".searchBar").removeClass("fadeOut")
});


addClass("overlayon") won't work ?!?!?

fadeIn works

fadeOut works



the entire js can be seen here:
https://github.com/TerminalAddict/ta.com-website/blob/master/assets/js/ta.js



I'm using to yui-compressor to compress, then create one big bundle (bundle.js)



no errors in console, and if I paste this function into the console it works fine.



Live demo: https://terminaladdict.com










share|improve this question







New contributor




TerminalAddict is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • I've also tried: $("fadeOut").on("click", "input", function(a) { a.preventDefault(); $(".nooverlay").addClass("overlayon"); $(".searchBar").addClass("fadeIn"); $(".searchBar").removeClass("fadeOut") });
    – TerminalAddict
    Nov 5 at 2:49












  • What's the purpose of the classes nooverlay and overlayon?
    – D. Smania
    Nov 5 at 3:05










  • overlayon to create a 100% height 100% width overlay with with opaque background, that is clickable (to close the searchbar) nooverlay, because I though jquery was getting confused by not having an original class
    – TerminalAddict
    Nov 5 at 3:20













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I've got a strange problem where "most" of my rules work inside a click function, but one won't



$(".fadeOut input").click(function() {
$(".nooverlay").addClass("overlayon");
$(".searchBar").addClass("fadeIn");
$(".searchBar").removeClass("fadeOut")
});


addClass("overlayon") won't work ?!?!?

fadeIn works

fadeOut works



the entire js can be seen here:
https://github.com/TerminalAddict/ta.com-website/blob/master/assets/js/ta.js



I'm using to yui-compressor to compress, then create one big bundle (bundle.js)



no errors in console, and if I paste this function into the console it works fine.



Live demo: https://terminaladdict.com










share|improve this question







New contributor




TerminalAddict is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I've got a strange problem where "most" of my rules work inside a click function, but one won't



$(".fadeOut input").click(function() {
$(".nooverlay").addClass("overlayon");
$(".searchBar").addClass("fadeIn");
$(".searchBar").removeClass("fadeOut")
});


addClass("overlayon") won't work ?!?!?

fadeIn works

fadeOut works



the entire js can be seen here:
https://github.com/TerminalAddict/ta.com-website/blob/master/assets/js/ta.js



I'm using to yui-compressor to compress, then create one big bundle (bundle.js)



no errors in console, and if I paste this function into the console it works fine.



Live demo: https://terminaladdict.com







jquery click






share|improve this question







New contributor




TerminalAddict is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




TerminalAddict is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




TerminalAddict is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 5 at 2:34









TerminalAddict

83




83




New contributor




TerminalAddict is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





TerminalAddict is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






TerminalAddict is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • I've also tried: $("fadeOut").on("click", "input", function(a) { a.preventDefault(); $(".nooverlay").addClass("overlayon"); $(".searchBar").addClass("fadeIn"); $(".searchBar").removeClass("fadeOut") });
    – TerminalAddict
    Nov 5 at 2:49












  • What's the purpose of the classes nooverlay and overlayon?
    – D. Smania
    Nov 5 at 3:05










  • overlayon to create a 100% height 100% width overlay with with opaque background, that is clickable (to close the searchbar) nooverlay, because I though jquery was getting confused by not having an original class
    – TerminalAddict
    Nov 5 at 3:20


















  • I've also tried: $("fadeOut").on("click", "input", function(a) { a.preventDefault(); $(".nooverlay").addClass("overlayon"); $(".searchBar").addClass("fadeIn"); $(".searchBar").removeClass("fadeOut") });
    – TerminalAddict
    Nov 5 at 2:49












  • What's the purpose of the classes nooverlay and overlayon?
    – D. Smania
    Nov 5 at 3:05










  • overlayon to create a 100% height 100% width overlay with with opaque background, that is clickable (to close the searchbar) nooverlay, because I though jquery was getting confused by not having an original class
    – TerminalAddict
    Nov 5 at 3:20
















I've also tried: $("fadeOut").on("click", "input", function(a) { a.preventDefault(); $(".nooverlay").addClass("overlayon"); $(".searchBar").addClass("fadeIn"); $(".searchBar").removeClass("fadeOut") });
– TerminalAddict
Nov 5 at 2:49






I've also tried: $("fadeOut").on("click", "input", function(a) { a.preventDefault(); $(".nooverlay").addClass("overlayon"); $(".searchBar").addClass("fadeIn"); $(".searchBar").removeClass("fadeOut") });
– TerminalAddict
Nov 5 at 2:49














What's the purpose of the classes nooverlay and overlayon?
– D. Smania
Nov 5 at 3:05




What's the purpose of the classes nooverlay and overlayon?
– D. Smania
Nov 5 at 3:05












overlayon to create a 100% height 100% width overlay with with opaque background, that is clickable (to close the searchbar) nooverlay, because I though jquery was getting confused by not having an original class
– TerminalAddict
Nov 5 at 3:20




overlayon to create a 100% height 100% width overlay with with opaque background, that is clickable (to close the searchbar) nooverlay, because I though jquery was getting confused by not having an original class
– TerminalAddict
Nov 5 at 3:20












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










As input box you are target is having an ID and Div element where you are trying to add class is also have an ID. ID's are unique and I think you can use below piece of code. That i also tried executing on console window and seems to be working.



$("#query").click(function(e){
event.preventDefault();

if($('#query').parents('.fadeOut').length>0){
$('#overlay').addClass('overlayon');
$('.searchBar').addClass('fadeIn');
$('.searchBar').removeClass('fadeOut');
}
});


As We have Black Background to appear only in case of .fadeout class So I have added below code in jquery code above to check if parent of Query Textbox has that class. It seems to be working fine.



 if($('#query').parents('.fadeOut').length>0){





share|improve this answer























  • makes no difference sorry
    – TerminalAddict
    Nov 5 at 3:35










  • as you also have id to that element can you try with id instead of class like $('#overlay').addclass('overlayon');
    – Heemanshu Bhalla
    Nov 5 at 3:42












  • I need to target $('fadeOut #query) as I don't want this to run when the searchBar is fadeIn .. let me try
    – TerminalAddict
    Nov 5 at 4:12












  • @TerminalAddict I have updated above code it seems to be working fine on console for all 3 rules. code you gave in question was not working on console also.
    – Heemanshu Bhalla
    Nov 5 at 4:14






  • 1




    legend !!! that did the trick ! Thanks so much
    – TerminalAddict
    Nov 5 at 4:28











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






TerminalAddict is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147596%2fjquery-click-function-addclass%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










As input box you are target is having an ID and Div element where you are trying to add class is also have an ID. ID's are unique and I think you can use below piece of code. That i also tried executing on console window and seems to be working.



$("#query").click(function(e){
event.preventDefault();

if($('#query').parents('.fadeOut').length>0){
$('#overlay').addClass('overlayon');
$('.searchBar').addClass('fadeIn');
$('.searchBar').removeClass('fadeOut');
}
});


As We have Black Background to appear only in case of .fadeout class So I have added below code in jquery code above to check if parent of Query Textbox has that class. It seems to be working fine.



 if($('#query').parents('.fadeOut').length>0){





share|improve this answer























  • makes no difference sorry
    – TerminalAddict
    Nov 5 at 3:35










  • as you also have id to that element can you try with id instead of class like $('#overlay').addclass('overlayon');
    – Heemanshu Bhalla
    Nov 5 at 3:42












  • I need to target $('fadeOut #query) as I don't want this to run when the searchBar is fadeIn .. let me try
    – TerminalAddict
    Nov 5 at 4:12












  • @TerminalAddict I have updated above code it seems to be working fine on console for all 3 rules. code you gave in question was not working on console also.
    – Heemanshu Bhalla
    Nov 5 at 4:14






  • 1




    legend !!! that did the trick ! Thanks so much
    – TerminalAddict
    Nov 5 at 4:28















up vote
0
down vote



accepted










As input box you are target is having an ID and Div element where you are trying to add class is also have an ID. ID's are unique and I think you can use below piece of code. That i also tried executing on console window and seems to be working.



$("#query").click(function(e){
event.preventDefault();

if($('#query').parents('.fadeOut').length>0){
$('#overlay').addClass('overlayon');
$('.searchBar').addClass('fadeIn');
$('.searchBar').removeClass('fadeOut');
}
});


As We have Black Background to appear only in case of .fadeout class So I have added below code in jquery code above to check if parent of Query Textbox has that class. It seems to be working fine.



 if($('#query').parents('.fadeOut').length>0){





share|improve this answer























  • makes no difference sorry
    – TerminalAddict
    Nov 5 at 3:35










  • as you also have id to that element can you try with id instead of class like $('#overlay').addclass('overlayon');
    – Heemanshu Bhalla
    Nov 5 at 3:42












  • I need to target $('fadeOut #query) as I don't want this to run when the searchBar is fadeIn .. let me try
    – TerminalAddict
    Nov 5 at 4:12












  • @TerminalAddict I have updated above code it seems to be working fine on console for all 3 rules. code you gave in question was not working on console also.
    – Heemanshu Bhalla
    Nov 5 at 4:14






  • 1




    legend !!! that did the trick ! Thanks so much
    – TerminalAddict
    Nov 5 at 4:28













up vote
0
down vote



accepted







up vote
0
down vote



accepted






As input box you are target is having an ID and Div element where you are trying to add class is also have an ID. ID's are unique and I think you can use below piece of code. That i also tried executing on console window and seems to be working.



$("#query").click(function(e){
event.preventDefault();

if($('#query').parents('.fadeOut').length>0){
$('#overlay').addClass('overlayon');
$('.searchBar').addClass('fadeIn');
$('.searchBar').removeClass('fadeOut');
}
});


As We have Black Background to appear only in case of .fadeout class So I have added below code in jquery code above to check if parent of Query Textbox has that class. It seems to be working fine.



 if($('#query').parents('.fadeOut').length>0){





share|improve this answer














As input box you are target is having an ID and Div element where you are trying to add class is also have an ID. ID's are unique and I think you can use below piece of code. That i also tried executing on console window and seems to be working.



$("#query").click(function(e){
event.preventDefault();

if($('#query').parents('.fadeOut').length>0){
$('#overlay').addClass('overlayon');
$('.searchBar').addClass('fadeIn');
$('.searchBar').removeClass('fadeOut');
}
});


As We have Black Background to appear only in case of .fadeout class So I have added below code in jquery code above to check if parent of Query Textbox has that class. It seems to be working fine.



 if($('#query').parents('.fadeOut').length>0){






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 5 at 4:13

























answered Nov 5 at 2:58









Heemanshu Bhalla

1,9351127




1,9351127












  • makes no difference sorry
    – TerminalAddict
    Nov 5 at 3:35










  • as you also have id to that element can you try with id instead of class like $('#overlay').addclass('overlayon');
    – Heemanshu Bhalla
    Nov 5 at 3:42












  • I need to target $('fadeOut #query) as I don't want this to run when the searchBar is fadeIn .. let me try
    – TerminalAddict
    Nov 5 at 4:12












  • @TerminalAddict I have updated above code it seems to be working fine on console for all 3 rules. code you gave in question was not working on console also.
    – Heemanshu Bhalla
    Nov 5 at 4:14






  • 1




    legend !!! that did the trick ! Thanks so much
    – TerminalAddict
    Nov 5 at 4:28


















  • makes no difference sorry
    – TerminalAddict
    Nov 5 at 3:35










  • as you also have id to that element can you try with id instead of class like $('#overlay').addclass('overlayon');
    – Heemanshu Bhalla
    Nov 5 at 3:42












  • I need to target $('fadeOut #query) as I don't want this to run when the searchBar is fadeIn .. let me try
    – TerminalAddict
    Nov 5 at 4:12












  • @TerminalAddict I have updated above code it seems to be working fine on console for all 3 rules. code you gave in question was not working on console also.
    – Heemanshu Bhalla
    Nov 5 at 4:14






  • 1




    legend !!! that did the trick ! Thanks so much
    – TerminalAddict
    Nov 5 at 4:28
















makes no difference sorry
– TerminalAddict
Nov 5 at 3:35




makes no difference sorry
– TerminalAddict
Nov 5 at 3:35












as you also have id to that element can you try with id instead of class like $('#overlay').addclass('overlayon');
– Heemanshu Bhalla
Nov 5 at 3:42






as you also have id to that element can you try with id instead of class like $('#overlay').addclass('overlayon');
– Heemanshu Bhalla
Nov 5 at 3:42














I need to target $('fadeOut #query) as I don't want this to run when the searchBar is fadeIn .. let me try
– TerminalAddict
Nov 5 at 4:12






I need to target $('fadeOut #query) as I don't want this to run when the searchBar is fadeIn .. let me try
– TerminalAddict
Nov 5 at 4:12














@TerminalAddict I have updated above code it seems to be working fine on console for all 3 rules. code you gave in question was not working on console also.
– Heemanshu Bhalla
Nov 5 at 4:14




@TerminalAddict I have updated above code it seems to be working fine on console for all 3 rules. code you gave in question was not working on console also.
– Heemanshu Bhalla
Nov 5 at 4:14




1




1




legend !!! that did the trick ! Thanks so much
– TerminalAddict
Nov 5 at 4:28




legend !!! that did the trick ! Thanks so much
– TerminalAddict
Nov 5 at 4:28










TerminalAddict is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















TerminalAddict is a new contributor. Be nice, and check out our Code of Conduct.













TerminalAddict is a new contributor. Be nice, and check out our Code of Conduct.












TerminalAddict is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147596%2fjquery-click-function-addclass%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()