Switch... Break, breaks the jquery "each" loop [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 days ago.
Improve this question
I got an unexpected behavior using switch...break.. in a "each" function. The "break" breaks completely the "each" loop.
Here is a code (simplified):
$('input[type="number"').each(function(){
switch ($(this).attr('id))
case 'id1': // do stuff
break;
}
actually, I have 4 INPUT matching the selector, but everything stops at the first one after the break is executed.
I was expecting the break to exit the switch, not stop the loop.
Any idea?
Thanks.
The break will exit the Switch, but doesn't stop the "each".

Related

jquery click event firing simultaneously [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have some jquery code which handles some click events but i've ran into a problem where its firing both click events ive tried binding/unbinding them but not worked as i wanted it to. I've created a simplified version of it for demo.
jQuery('.tabs').click(function(e){
jQuery(this).toggleClass('active');
});
// jQuery('close_slide').click(function()){
// jQuery(this).parent().parent().removeClass('active');
// });
// Not part of Original question.
// But fixing the typos as they wony cause mention issue.
// Credits: #Jonas W.
jQuery('.close_slide').click(function() {
jQuery(this).parent().parent().removeClass('active');
});
The close slide element is inside of tabs so when i click the close slide element it doesnt remove as expected/
Thanks
Just stop the events propagation:
jQuery('.close_slide').click(function(evt) {
evt.stopPropagation();
jQuery(this).parent().parent().removeClass('active');
});

onClick event executes as soon as I change the function [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
i am trying to change the onclick value of a Button via Javascript. But in the moment I change its value, the function is executed directly.
document.getElementById('Send').disabled = false;
document.getElementById('Send').addEventListener("click", window.location.href = 'http://www.google.com');
Second parameter must be a function! Try:
document.getElementById('Send')
.addEventListener("click",
function(){window.location.href = 'http://www.google.com'});

$(Element).outerWidth() is returning element's DOM instead of width [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have a div which outerwidth () returns the selector itself in an array
For $('.slidePopup').outerWidth() its returning like this
<div class=​"slidePopup">​
​......​
<div class=​"sildeInside">​ ​</div>
​</div>​
Has someone else faced the same issue?
It seems this is an existing bug and fixed in older version.
https://bugs.jquery.com/ticket/12491
Please check whether you are using latest version of jQuery. If not consider upgrading to latest version of jQuery or pass "false" as argument as mentioned in the link

Jquery slide down menu if else condition [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to build a slide down menu using JQuery. I thought I'd base it around this logic, that if the menu had the class activated then when it is clicked it should be closed. Otherwise it is not open so it should be open.
The code below is a basic version of what I'm trying to achieve, but for some reason it never gets into the clause. Every time I click the item the alert box saying "Close" comes up.
$('#openMenu').click(function(){
if($('#openMenu'.hasClass('activated'))){
alert('close');
$(this).removeClass('activated');
}else{
alert('open');
$(this).addClass('activated');
}
});
Can anyone see where I might be going wrong? I should point out that when the page loads the div does not have the class activated applied to it.
$('#openMenu').toggleClass("activated");
It seems like your syntax for checking the element's class has issues, it should look like this:
if($('#openMenu').hasClass('activated')){
Here is the working fiddle:
http://jsfiddle.net/dnsdrzym/2/

How to pass javascript variable in class? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am writing a code for quiz,whenever one option is selected by the user from out of four option,i want to alert. I have something similar to my code here:-
<label class="alert optiona">
</lablel>
I am having value
data.correct="optiona";
I need to send pass the value in javascript.When i am passing following syntax , it doesnt send the value of data.correct.
$(".alert "+data.correct).attr("class", "alert alert-"+ data.mode);
You're missing the dot in the selector and you have a space which means that the second class applies to a descendant of the .alert element.
Change
$(".alert "+data.correct)
to
$(".alert."+data.correct)

Categories

Resources