最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery change cursor on click on link - Stack Overflow

programmeradmin1浏览0评论

How I can change the cursor CSS property of a link element, so when the user click on that link, the cursor switches from pointer to wait?

jQuery(document).ready(function(){
  jQuery('a.cursor_wait').click(function(){
    jQuery('body').css('cursor', 'wait');
  });
});

This works, but I must move with the mouse from the link to see the wait indicator, when I leave my cursor on the link, I still see the pointer.

How can I make this work without moving my cursor?

How I can change the cursor CSS property of a link element, so when the user click on that link, the cursor switches from pointer to wait?

jQuery(document).ready(function(){
  jQuery('a.cursor_wait').click(function(){
    jQuery('body').css('cursor', 'wait');
  });
});

This works, but I must move with the mouse from the link to see the wait indicator, when I leave my cursor on the link, I still see the pointer.

How can I make this work without moving my cursor?

Share Improve this question edited Aug 14, 2021 at 19:16 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Feb 16, 2011 at 16:02 astropanicastropanic 10.9k20 gold badges74 silver badges132 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 1

Example

http://jsfiddle/loktar/3WLGt/4/

JS

jQuery(document).ready(function(){
  jQuery('a.cursor_wait').click(function(){
    jQuery('body').css('cursor', 'wait');
      jQuery(this).css('cursor', 'wait');
  });
});

Changes the property of the current link to the wait cursor as well, because by default they are set to pointer.

you want only wait cursor on your link? so why select body and change cursor?!

$('a').css('cursor','wait');

Try this (not tested) :

jQuery('body').trigger('hover');

if I understand correctly , you want click on a link ( for example DELETE an item ) then change the courser to wait until your request will be done, turn it back to default...

var c= confirm("Are you sure?");
if(c)
{ 
    document.body.style.cursor="wait";
    $.post("delete.php?id=212",function(data){
        alert('I\'ve done it...');
        document.body.style.cursor="default";
    });
} 

I got it to work changing the class of the a, and changing the jquery to $ as below:

$(document).ready(function() {
    $('a').click(function() {
        $('body').css('cursor', 'wait');
        $(this).css('cursor', 'wait');
    });
});

However, this will work for all anchor tags a. You will need to specify the css class you want it to apply to.

发布评论

评论列表(0)

  1. 暂无评论