I have tried everything to get it to toggle show and hide but every time I add hide in the function, it stops working or I can get hide to work flawlessly while show doesn't work at all. Any help would be appreciated.
<div class="ShowHideClicker clear" >
<img src="something.gif"></div> <div class="ShowHideList">
<div class="ui-widget" id="SearchBar">
<label for="tags">Search:</label>
<input id="tags">
<button class='clear' id="ClearButton"> Clear</button>
</div>
<div id="Result"></div>
</div>
$(document).ready(function(){
$('.ShowHideList').hide();
$('.ShowHideClicker').click(function(){
$(this).next().show('drop', {direction: 'left'}, 1000);
});
});
Here is the simple solution with toggleClass:
$('.ShowHideClicker').on('click', function(){
$(this).next().toggleClass('hidden');
});
http://jsfiddle.net/LcYLY/
You should be using the .toggle() this way: JSFIDDLE and make sure you have included jQuery and jQuery UI in your header ("drop" is a jQuery UI feature)
jQuery:
$(document).ready(function(){
$('.ShowHideClicker').click(function(){
$('.ShowHideList').toggle('drop', 1000);
});
});
CSS:
.ShowHideList { display: none; }
Related
The code below is working in a jfiddle, but once on my WordPress site it's not firing. I am updated to 4.6.1. I can't seem to find any errors in the console, either. Any ideas?
CSS:
<style>.bluebg { background: cyan; }</style>
HTML:
<nf-field>
<div class="nf-field-container textbox-container label-left ">
<div class="nf-before-field"><nf-section></nf-section></nf-section></div>
<div class="nf-field"><div id="nf-field-8-wrap" class="field-wrap textbox-wrap nf-pass" data-field-id="8">
<div class="nf-field-label">
<label for="nf-field-8" class="">Full Name <span class="ninja-forms-req-symbol">*</span></label></div>
<div class="nf-field-element">
<input id="nf-field-8" name="nf-field-8" class="ninja-forms-field nf-element" value="" type="text">
</div>
</div>
</div>
<div class="nf-after-field"><nf-section><div class="nf-input-limit"></div><div class="nf-error-wrap nf-error"></div></nf-section>
</div>
</div>
</nf-field>
JAVASCRIPT:
<script>
$('input.nf-element').bind('focus blur', function () {
$(this).closest('nf-field').find('.nf-field-container').toggleClass('bluebg');
});
</script>
UPDATE
It looks like the problem is in the plugin that is generating the HTML, not the javascript I'm using. If I paste the same HTML in manually, that input field does change the parent class, but none of the fields that the form plugin generates (NinjaForms) will change.
I'm not sure if that's out of scope for assistance here, but if anyone has any ideas why that would be, I'd be appreciative!
Simply replace "$" with "jQuery".
To account for wordpress likely using jQuery.noConflict() try changing to:
(function($) {
$(function() {
$('input.nf-element').on('focus blur', function() {
$(this).closest('nf-field').find('.nf-field-container').toggleClass('bluebg');
});
});
})(jQuery);
I have three buttons and each one has a CSS class. At click of one of them, i would like remove the class and add a new CSS class only for the clicked element. Furthermore, I need to keep pressed the selected button.
I searched some examples and I found that is possible do something like this:
$(".class").removeClass("choice").addClass("active");
This works for all buttons, but not only for one. I try to change this in
$(this).removeClass("choice").addClass("active");
but this didn't work.
I make a fiddle for more compreansion: https://jsfiddle.net/90u6b3tj/3/
EDIT
I need the same behavior when i press a second time
Sorry for the basic problem.
Thanks in advance
Regards
I've updated your jsfiddle for a working solution:
https://jsfiddle.net/90u6b3tj/10/
Here's the javascript part:
$(function() {
$("button").click(function(e) {
e.preventDefault();
$(this).toggleClass("active");
});
});
as you are adding your click events like so:-
<button id="hourly" class="choice" onclick="change()">Orario</button>
you could use event.target:-
function change(){
event.preventDefault();
$(event.target).removeClass("choice").addClass("active");
}
OR, change your event and pass in this:-
<button id="hourly" class="choice" onclick="change(this)">Orario</button>
so you can do:-
function change(element){
event.preventDefault();
$(element).removeClass("choice").addClass("active");
}
OR better still:-
$('.choice').click(function(e){
e.preventDefault();
$(this).removeClass("choice").addClass("active");
});
and remove the inline click event.
You can use the following code instead.
$(".class").click(function(){
$(".class").addClass("choice");
$(".class").removeClass("active");
$(this).removeClass("choice").addClass("active");
});
Here, the "choice" class is removed only from the clicked class. Not from the others. Also the "active" class is added to the clicked one.
You may use change(this) in your button markup and refer to that element in your change() function, as shown in this fiddle.
function change(event){
event.preventDefault();
//$(".choice").removeClass("choice").addClass("active");
$(event.target).removeClass("choice").addClass("active");
}
<div>
<button id="hourly" class="choice" onclick="change(event)">Orario</button>
</div>
<div>
<button id="daily" class="choice" onclick="change(event)">Giornaliero</button>
</div>
<div>
<button id="monthly" class="choice" onclick="change(event)">Mensile</button>
</div>
Should it possible so select more than one item as active?
If not, checkout this:
Markup
<div>
<button id="hourly" class="choice">Orario</button>
</div>
<div>
<button id="daily" class="choice">Giornaliero</button>
</div>
<div>
<button id="monthly" class="choice">Mensile</button>
</div>
CSS
.active {
background-color: #A60076;
color: #FF0000;
}
.choice {
background-color: #000000;
color: #FFFFFF;
}
JS
$(document).ready(function() {
$('button').click(function(e) {
$("button").addClass('choice').removeClass('active');
$(this).removeClass('choice').addClass('active');
});
});
Here is a sample fiddle with the above code working.
i need a little help about how to do it..
I have done lot of search but haven't find it.. So please if someone can help me out.
I have this little code here:-
<div id="whats-new-content">
<div class="newtextbox">
<textarea class="mytextbox" id="myuniquetextbox" cols="50" rows="10" style="height: 50px;"></textarea>
</div>
<div id="whats-new-options" style="display: none;">
<input type="submit" name="aw-whats-new-submit" id="aw-whats-new-submit" value="Submit">
</div>
</div>
As you can see i added style="display: none;" in the div where is situated the submit button.
I don't have lot of knowledge in jQuery or javascript but i need a simple javascript code that will change the "display:none" to "display:block" when someone click on the textbox..
Please i need your help, thank you very much...
Another way to do this is:
$(function () {
$('#myuniquetextbox').click(function(e) {
$('#whats-new-options').css('display', 'block');
});
});
Try this
$("#myuniquetextbox").on("focus",function(){
$("#whats-new-options").show();
})
Try below code
$("#mytextbox").focus(function() {
// this is when textarea is focused and button should show
$("#whats-new-options").show();
});
$("#mytextbox").blur(function() {
// this is when textarea is not focused and button should hide
$("#whats-new-options").hide();
});
Try using bellow
<script>
$("#myuniquetextbox").click(function(){
$("#aw-whats-new-submit").slideToggle();
});
</script>
$("#aw-whats-new-submit").hide();
$("#myuniquetextbox").click(function() {
$("#aw-whats-new-submit").show();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="whats-new-content">
<div class="newtextbox">
<textarea class="mytextbox" id="myuniquetextbox" cols="50" rows="10" style="height: 50px;"></textarea>
</div>
<div id="whats-new-options" >
<input type="submit" name="aw-whats-new-submit" id="aw-whats-new-submit" value="Submit">
</div>
</div>
you can also do this
$(function () {
$('#myuniquetextbox').on('click',function(e) {
$('#whats-new-options').css('display', 'block');
});
});
Check your code here
Hi I am making an effect that is when Mouse Enter in div one button shows in that div and when user mouse leave that area again button hide.
It works but the problem is that I have used div many times so I have used class for div definition.
So when Mouse enter in one div other div also affected.
Code :
jQuery:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#container").mouseenter(function(){
$(":button").show();
});
$("#container").mouseleave(function(){
$(":button").hide();
});
});
</script>
jsp code :
<div id="container">
<div class="mainitemlist">
<div class="mainitemlistimage">
<a href="product?pid=3">
<img src="product_images/Tulips1760331818.jpg" height="125px" width="100px" style="border-radius:2px;">
</a>
</div>
<div class="mainitemlistname"><div align="center">Nokia Lumia 925</div></div>
<div class="mainitemlistprice"><div align="center">38000</div></div>
<div class="mainitemlistfeatures"><div align="center">null</div>
<button type="button" style="display: none;">Hide me</button></div>
</div>
<div class="mainitemlist">
<div class="mainitemlistimage">
<a href="product?pid=5">
<img src="product_images/Jellyfish456319058.jpg" height="125px" width="100px" style="border-radius:2px;">
</a>
</div>
<div class="mainitemlistname"><div align="center">HCL Me</div></div>
<div class="mainitemlistprice"><div align="center">40000</div></div>
<div class="mainitemlistfeatures"><div align="center">null</div>
<button type="button" style="display: none;">Hide me</button></div>
</div>
</div>
I have try to put Jquery on class="mainitemlist" but It's not working.
So I have added in id="container".
Anyone have idea, why it's not working ???
You can do this:
$(document).ready(function () {
$(".mainitemlist").mouseenter(function () {
$(this).find(":button").show();
}).mouseleave(function () {
$(this).find(":button").hide();
});
});
Demo: Fiddle
When you used the class mainitemlist you were not using the function scope properly using $(this) and hence it showing all the button on mouseenter, since you used the code:
$(":button").show();
UPDATE
$(document).ready(function () {
$(document).on('mouseenter', '.mainitemlist', function () {
$(this).find(":button").show();
}).on('mouseleave', '.mainitemlist', function () {
$(this).find(":button").hide();
});
});
try:
$(document).ready(function(){
$("#container").mouseenter(function(){
$("#container button").show();
});
$("#container").mouseleave(function(){
$("#container button").hide();
});
});
check out this fiddle.
b.t.w, you have 2 divs with the id of container. this is probably a mistake, and if not, it's bad practice.
hope that helps.
$("#container").mouseenter(function(){
$(this).find('#yourbutton').show();
});
$("#container").mouseleave(function(){
$(this).find('#yourbutton').hide();
});
i'm trying to use jQuery to add/remove a class to an element but I only want to target the '.content' class that is directly above the '.trigger' essentially making each work independently of each other.
Any ideas on the best way to do this?
Thanks in advance
HTML
<div class="instance">
<span class="content showHide">this is hidden</span>
trigger
</div>
<br />
<div class="instance">
<span class="content showHide">this is hidden</span>
trigger
</div>
<br />
<div class="instance">
<span class="content showHide">this is hidden</span>
trigger
</div>
CSS
<style type="text/css">
.showHide{
display: none;
}
</style>
JS
<script type="text/javascript">
$(document).ready(function(){
$('.instance a.trigger').click(function(){
$('span.content').toggleClass('showHide');
});
});
</script>
Try using .prev() that will only target the .content element which is a immediately preceding sibling of your .trigger element:
$(document).ready(function(){
$('.instance a.trigger').click(function(){
$(this).prev('span.content').toggleClass('showHide');
});
});
You could also use siblings(). It will only target everything in the same container
$(document).ready(function(){
$('.instance a.trigger').click(function(){
$(this).siblings('span.content').toggleClass('showHide');
});
});
Fiddle
This method will allow the .content to be anywhere in the container, whether it is before or after the .trigger