highlight a DOM element on mouse over, like inspect does

后端 未结 2 1206
伪装坚强ぢ
伪装坚强ぢ 2020-12-28 09:16

We have a bookmarklet, and the user clicks a button and an inspect like highligther needs to kick in. We want to this to be cross browser.

For this we need to detec

2条回答
  •  醉酒成梦
    2020-12-28 09:47

    With the help of jquery you can do something like this

    $('*').hover(
        function(e){
            $(this).css('border', '1px solid black');
            e.preventDefault();
            e.stopPropagation();
            return false;
        },function(e){
            $(this).css('border', 'none');
            e.preventDefault();
            e.stopPropagation();
            return false;
        }
    );
    

    With this code in your bookmarklet, you can load what ever code

    javascript:function loadScript(src){f=document.createElement('script');if(f){f.setAttribute("type","text/javascript");f.setAttribute("src",src);document.getElementsByTagName("head")[0].appendChild(f);}};loadScript("yourscripturl");
    

提交回复
热议问题