javascript - DataTable How to prevent row click in columns containing hyperlinks -
i dealing javascript datatable clickable rows. each row when clicked forwards browser different page. column of row contains hyperlink. when hyperlin clicked don't want row click event fired or managed.
here how have implemented row click event
$(tableid+' tbody').on( 'click', 'tr', function (e) { window.location.href = $(this).attr('url'); });
when add event listener parent, event default "bubbles" downwards , attaches event children. in case setting event on tr
(parent) , event bubble down , attach td
(children). 1 of these td
understand contains href
(hyperlink) , block click
event set on parent, have set event listener of event type click
within function event need state event.stoppropagation()
, override tr
click event bubbled down.
document.addeventlistener('domcontentloaded',()=>{ //set event on parent(tr), event bubbles default downwards therefore td's inherit document.getelementbyid('parent').addeventlistener('click',()=>window.location.href = "wherever"); //adding event listener of same type (click) blocks bubbling propogation downards document.getelementbyid('myhyperlink').addeventlistener('click',(e)=>event.stoppropagation()); });
Comments
Post a Comment