Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bind function to DOM events once and only once so that they will not execute for a second time in the triggering of event?
    primarykey
    data
    text
    <p>so I have anchor tags in the form of <code>&lt;a href='[link'] rel='Tab'&gt;</code> and I apply the following at page load:('document ready' I mean) </p> <pre><code>jQuery("a[rel*=Tab]").click(function(e) { e.preventDefault();//then I do some stuff to open it in jq ui tab} </code></pre> <p>now the problem is that when I do this and later through javascript new links are generated, in my case with loading a second page with JqGrid there are new <code>&lt;a rel='neoTab'&gt;</code>'s that did not exist when I first run <code>jQuery("a[rel*=Tab]").click(function(e)</code> so they won't work... so I can run <code>jQuery("a[rel*=Tab]").click(function(e)</code> at every event that creates new links but then the old links would load multiple tabs so is there a way I could select all the "<code>a[rel*=Tab]</code>"s that were not not selected before?</p> <p><strong>note:</strong> I can and have already solved this through an algorithmic approach as you can see through the details below, I just think there is some syntaxes I am not aware of to prevent the need to use this hack!</p> <p><strong>Unnecessary Details:</strong></p> <pre><code>var neoTabitStat = 0; var openTabs = new Array(); openTabs[0] = 'inbox'; if(!(currentBox=='inbox'||currentBox=='outbox') ) {var currentBox = 'inbox';} function initNeoTab(a){ if(neoTabitStat==0) { jQuery("a[rel*="+a+"]").click(function(e) { e.preventDefault(); tabIt(jQuery(this).attr('href')+'&amp;nohead=1',jQuery(this).attr('title'),jQuery(this).attr('data-hovercard')); }); neoTabitStat++; } } function tabIt(a,b,c) { c = typeof(c) != 'undefined' ? c : 0; lastOpen = openTabs.length; if(lastOpen&lt;6) { if(openTabs.indexOf(c)&lt;0) { openTabs[lastOpen] = c; jQuery("#tabs").tabs("add" , a , b, lastOpen+1 ); } $tabs.tabs('select', openTabs.indexOf(c) ); }else{ var tabErrDig = jQuery('&lt;div style="display:hidden"&gt;You have opened the maximum amount of tabs please close one to open another tab.&lt;/div&gt;').appendTo('body'); tabErrDig.dialog({width:500,title:'Maximum Tabs Opened',modal: true, buttons: { Ok: function() { jQuery( this ).dialog( "close" ); } } }); } } jQuery(document).ready(function() { initNeotab('nameOfrelAttr4existingLinks'); } myGrid = jQuery("#list").jqGrid({/*alot of stuff...*/} , gridComplete: function() { initNeotab('nameOfrelAttr4generatedLinks'); } </code></pre> <p><strong>UPDATE:</strong> as Wrikken suggested jQuery().live I checked it out and it is exactly what I need but I can't get it to actually work, it won't work in some cases. For everyone else who wrote different solutions, are you fimiliar with .live() if so why is it that I can't use it here?</p> <p><strong>CONCLUSION</strong> special thanks to fudgey, patrick dw, and wrikken. All answers were helpful. <a href="http://api.jquery.com/delegate/" rel="nofollow">.delegate()</a>. worked for me but for some reason <a href="http://api.jquery.com/live/" rel="nofollow">.live()</a> didn't. something about the way <a href="http://www.trirand.com/blog/" rel="nofollow">jqGrid</a> add's elements to the table. I'm gonna keep the question open for a while. Thanks alot again for all your help. +1 to all</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload