Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

detect click on link in all places javascript

function clickOrigin(e){
    var target = e.target;
    var tag = [];
    tag.tagType = target.tagName.toLowerCase();
    tag.tagClass = target.className.split(' ');
    tag.id = target.id;
    tag.parent = target.parentNode.tagName.toLowerCase();

    return tag;
}

var tagsToIdentify = ['img','a'];

document.body.onclick = function(e){
    elem = clickOrigin(e);

    for (i=0;i<tagsToIdentify.length;i++){
        if (elem.tagType == tagsToIdentify[i] && elem.parent == 'a'){
            console.log('You've clicked a monitored tag (' + elem.tagType + ', in this case and one inside an "a" element, no less!).');
            return false; // or do something else.
        }
        else if (elem.tagType == tagsToIdentify[i]){
            console.log('You've clicked a monitored tag (' + elem.tagType + ', in this case).');
            return false; // or do something else.
        }
    }
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: js try catch err.printstacktrace 
Javascript :: loop array 
Javascript :: angular component with attribute selector 
Javascript :: what does concurrently package do 
Javascript :: z-song laravel-admin unable load js fucntion untill use f5 
Javascript :: javascript code to jquery online 
Javascript :: select-deselect-event-handlers-datatable 
Javascript :: how to open same project on different devices vue js 
Javascript :: sinon chaining method 
Javascript :: how to write sepearet styles in single line in react native 
Javascript :: Read data in props.histroy.push in react component 
Javascript :: 4.5. Expressions and Evaluation¶ 
Javascript :: convert from python to javascript online 
Javascript :: how to share variables between routes node 
Javascript :: js rgba to hex 
Javascript :: react-leaflet/core/cjs/pane.js:7%20error15-Jun-2021%2000:45:06%20%20%20%20%20%20const%20pane%20=%20props.pane%20??%20context.pane; 
Javascript :: connecting , creating ,reading from mongo 
Javascript :: strict scalar types 
Javascript :: && in react jsx 
Javascript :: how to check if an image exists in js from cross origin 
Javascript :: how to convert serilazed data to json in js 
Javascript :: no longer in view js 
Javascript :: regex to get first word after slash in URL 
Javascript :: micromodal scrolls to bottom 
Javascript :: aurelia shadow dom 
Javascript :: how to pop more then one element js 
Javascript :: hide component blur react hooks 
Javascript :: how to reset count in react 
Javascript :: add if condition in map react 
Javascript :: jquery 3.2 1 min js download 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =