Jquery slide down menu if else condition [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 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/

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');
});

How to append data value to dynamically created div? [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'm attempting to associate a data value with a div created dynamically, however I have not been able to get this to work. I've tried looking around online but can't seem to adapt any examples to fit my problem. If anyone could help I would be very appreciative. The error I'm getting says that:
.data is not a function
If I try putting the $ operator in front control just passes right through my block of code and nothing happens.
var container = $("#container");
('<div class="orb"></div>').data(num).appendTo(container);
It works well:
var $container = $('#container');
$('<div class="orb"></div>').data('num', 123).appendTo($container);
console.log($('.orb').data('num'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="container"></div>
What is your problem?

jquery change css on radiobutton checked [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
below i have my fiddle which i want to change the text color when the radio button is selected. However i cant get it to work. at the moment it isnt firing at all and i cant get the div css to change.
$(".package-container").click(function () {
$(this).closest('.radio-group-row').find('.package-title').removeClass('highlight');
$(this).find('input:radio').prop('checked', true);
$(this).find('.package-title').addClass('highlight');
});
http://jsfiddle.net/46jGT/3/
EDIT
Thanks, it does work with the JSFiddle, but in my .net project i cant get this peice to work. i have jquery 1.9 referenced at the bottom on the master page with this code on the control page.
As mentioned in comments, you're missing the jquery library. Your code is working fine as it is once the library is added

How to click a link using jquery or javascript? [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 have a link:
Manage Lists
I want to "click" this link using jquery or javascript. I've tried:
$("#panel2-2").click(function(){});
$("#panel2-2").trigger('click');
It doesn't work! How can I do a click like this using javascript?
You need to use the jQuery attribute equals selector.
Description: Selects elements that have the specified attribute with a value exactly equal to a certain value.
For your case, you would use something like this:
$( "a[href='#panel2-2']" ).click();
You need
$('[href="#panel2-2"]').trigger('click');
or
$('[href="#panel2-2"]').click();

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