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
Please, why this Jquery doesn't Working
$(function(){
$('.accContainer').hide();
$('.accordion:first').next().slideDown("");
$('.accordion').click(function(){
if( $(this).next().is(':hidden') ) {
$('.accordion').next().slideUp();
$(this).next().slideDown();
}
return false;
});
});
code : http://www.jsfiddle.net/BQYQ5/22
You aren't closing h2:
Change:
<h2 class="accordion">-... <h2>
To:
<h2 class="accordion">-... </h2>
See updated fiddle
A better option than the code you have may be instead to use toggle, as what you have now won't allow you to close a tab that is opened. It will also simplify your code quite a bit.
$('.accordion').click(function(){
$(this).next().toggle();
return false;
});
JSFiddle
Related
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 1 year ago.
Improve this question
I am trying to get the element itself through making a function in the div itself I want when someone clicks on the current Element the Element should be deleted by fading in pure JavaScript I have searched on the internet but not getting the answer there are many similar questions on Stack Overflow but none of them giving me the combined answer(Like getting current element through Js in (inline function)).
So anyone can help me
<div style="width: 100px;height: 100px;background:red;" onclick="(function(ele){
console.log('helo')
console.log(ele.currentTarget)})();">
Thanks in advance
This should do it:
I added an id to your div which can be accessed through the getElementById.
<div id='hello' style="width: 100px;height: 100px;background:red;" onclick="
(
function() {
document.getElementById('hello').style.opacity = 0;
document.getElementById('hello').style.transition = '0.5s';
}
)();">
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I want to get the id from a class selector without clicking.
var type_selected = '' ;
$('.type_selected').attr();
type_selected = (this.id);
Use this. This will return an array of all elements with that class;
var type_selected = [];
$('.type_selected').each(function(){
type_selected.push($(this).attr("id"));
});
console.log(type_selected);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="type_selected" id="id1">This is a test<p>
<p class="type_selected" id="id2">This is a test 2<p>
<p class="type_selected" id="id3">This is a test<p>
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 new to javascript but I'm having a hard time toggle this class on and off.
https://jsfiddle.net/spadez/o2s0hmtv/2/
$( "#togglebtn" ).click(function() {
$(.mynav).toggleClass( "modal" );
});
Based on tutorials this should work, but the button doesn't seem to do anything. Can anyone show me where I went wrong please?
$( "#togglebtn" ).click(function() {
$(".mynav").toggleClass( "modal" );
});
Its just typo. Jquery selectors should be enclosed in '(single quotes) or "(double quotes) .
https://jsfiddle.net/o2s0hmtv/4/
$( "#togglebtn" ).click(function() {
$('.mynav').toggleClass( "modal" );
});
You need quotes around selectors (.mynav) here. Like this:
$( "#togglebtn" ).click(function() {
$('.mynav').toggleClass("modal");
});
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
(Code below) Trying to get a hover effect on the text in a div. Using class selectors in JQuery and it's not hitting when I use $('.abc') but does work when I use $('#top-nav-1') - not sure why it can't be hit when I select it by the secondary class. I can go through and use all the ids, but I'd rather just use one class - after all, that's what they're for!
Thanks, in advance, for the input on this.
HTML:
<div id="top-nav-1" class-"container abc">The Text</div>
CSS:
.container {
color: black;
}
JQuery:
$('.abc').hover(function() {
$(this).css('color','red');
});
fiddle: http://jsfiddle.net/yB9Jq/
You have a typo: class=, not class- (= not -).
Also, jQuery's .hover() takes two functions as arguments:
.hover( handlerIn(eventObject), handlerOut(eventObject) )
So an example would be:
$('.abc').hover(
function() {
$(this).css('color','red');
},
function() {
$(this).css('color','');
}
);
Your fiddle, updated.
Your markup is incorrect. You need to have class="container abc" instead of class-"container abc"
<div id="top-nav-1" class="container abc">The Text</div>
http://jsfiddle.net/yB9Jq/1/
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 6 years ago.
Improve this question
I am trying to do rich text editing with javascript and jquery.
I want to create a button to embolden selected text in a content editable div. When I tried with the following code, I get the expected result.
<div contenteditable="true" style="height:100px;width:100px;border:1px solid; " class="editor"></div>
<button class='bold' onclick="document.execCommand('bold',false,true);">B</button>
However, when I used jquery to do the same thing, it was not working.
<div contenteditable="true" style="height:100px;width:100px;border:1px solid; " class="editor"></div>
<button class='bold'>B</button>
$(function(){
$("button.class").on("click",function(){
document.execCommand('bold',false,true);
})
})
Why isn't jquery working for my problem ?
$("button.class").on("click",function(){
Change this to
$("button.bold").on("click",function(){
This is you can do and I hope this will definitely work.
$('.bold').click(function(){});