add spinner in the place of button on click event - javascript

I want to add a spinner below or in the place of the button on click event. I am trying with something like this.
not able to get this working.
Here's the fiddle.
<div class = "example test">
<img src="http://www.fordesigner.com/imguploads/Image/cjbc/zcool/png20080526/1211776983.png" onclick="$('.test').click();">
<div id="justamoment" style="text-align: left;font-family: Signika;color: white;font-size:14px;font-weight: bold;text-decoration: none;visibility:hidden">
<p>
<img src="http://www.ajaxload.info/cache/FF/FF/FF/00/00/00/1-0.gif" height="12" width="12" Just a moment..
</p>
</div>
<script>
$(".test").change(function(){
$("#justamoment").css("visibility","visible");
});
</script>
Please help.

You need to have a click handler not change
$(".test").click(function () {
$("#justamoment").css("visibility", "visible");
});
Demo: Fiddle

Try this
USe 'click' instead of 'change' . It will work
Wokring fiddle fine

What about this :
$(".test").click(function () {
$("#justamoment").css("visibility", "visible");
});
DEMO

Related

jQuery mouseenter event is not executed

I'm having some trouble with mouseenter event applied on div area in my pages. I'm trying to change background-color of this div on mouse enter but it is all just ignored.
I have a simple HTML CODE:
<div id="services" class="services">
<div id="services-top">
<h2>Services</h2>
</div>
<div id="services-content">
<div id="services-content-left">
<img id="services-content-right-img" class="img-circle" src="http://i.imgur.com/vN5m4vK.jpg" alt="empty">
<h3>STUFF</h3>
</div>
</div>
</div>
And JS stuff with this event:
$(document).ready(function() {
$("services-content-left").mouseenter(function() {
console.log("enter");
$(this).css("background-color", "yellow");
});
});
And as I said before, when I enter this div area, background stays the same, without any changes.
HERE is an example.
Don't you have any idea how to solve it?
Wrong selector :)
$(document).ready(function() {
$("#services-content-left").mouseenter(function() {
console.log("enter");
$(this).css("background-color", "yellow");
});
});
you simply missed out
out in your code, should be $("#services-content-left") instead
$(document).ready(function() {
$("#services-content-left").mouseenter(function() {
console.log("enter");
$(this).css("background-color", "yellow");
});
});
signify a ID selector.
You have missed a # before your services-content-left,
Please have it changed as,
$("#services-content-left").mouseenter(function() {
Working Fiddle: - https://jsfiddle.net/m2wpetp4/4/
Hope this helps!

Hide when no longer hovering using jQuery

I want the div #reloadWarningBackground to show ONLY when hovering over the button #reloadButton.
Here is my code:
$('#reloadButton').mouseover(function() {
$('#reloadWarningBackground').show();
});
Use mouseout like following.
$('#reloadButton').mouseover(function() {
$('#reloadWarningBackground').show();
}).mouseout(function() {
$('#reloadWarningBackground').hide();
})
UPDATE
It is better to use mouseenter since mouseover will be executed repeatedly.
$('#reloadButton').mouseenter(function () {
$('#reloadWarningBackground').show();
}).mouseleave(function () {
$('#reloadWarningBackground').hide();
})
The simplest and best way to address this problem is using toggle().
//html
<button id="reloadButton">
Hover me
</button>
<div id="reloadWarningBackground" style="display:none;">
<p>
Hello this is me
</p>
</div>
//Javascript
$('#reloadButton').hover(function() {
$('#reloadWarningBackground').toggle();
});
fiddle

JQuery Is not working properly on mouseenter and mouseleave

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

js slideUp doesn't work

I want to add slideUp effect to my page. My <body> code is:
<script>
$('#slide_up').click(function(){
$('p.text_study').slideUp('slow', function() {
$('#result').html("ok");
});
});
</script>
<img src="img/slide_up.png" alt="slide_up" id="slide_up">
<p class="text_study">Some text.</p>
<div id="result"></div>
When i click a button nothing happens. Please help.
Wrap it in $(document).ready. Your click handler is being assigned before the #slide_up element is ready for use:
$(document).ready(function(){
$('#slide_up').click(function(){
$('p.text_study').slideUp('slow', function() {
$('#result').html("ok");
});
});
});
JSFIDDLE http://jsfiddle.net/3uhCa/2/
Nothing wrong with your code. are you loading jquery correctly?
<img src="img/slide_up.png" alt="slide_up" id="slide_up">
<p class="text_study">Some text.</p>
<div id="result"></div>

jquery not() not working as expected

<div class="row">
<img src="images/image.png" width="30" height="30" alt=""/>
View
</div>
$(".row").not(".row a").click(function(){
// irrelevant
})
I can't figure out why this isn't working. I don't want to call the function when "View" is clicked.
Is this ,what you were looking for?
$(".row").on('click',':not(a)', function(){
});
Adds 'click' event listener on all child elements of '.row', except 'a' elements.
Use this:
$(".row").click(function(){
});
$('.row a').click(function(e){
e.stopPropagation(); //this cancel the other events
});

Categories

Resources