asp.net mvc 4 - jQuery get "distinct" elements from a document -



asp.net mvc 4 - jQuery get "distinct" elements from a document -

i creating footnotes helper asp.net mvc. have generated on page set of links similar to:

<a rel="footnote" href="#fn:footnote1" data-text="note" data-ref="1">1</a>

i want generate bottom section containing actual notes. goal take href , data-text each link , create li element @ bottom of page.

this html generated section:

<div id="6c708d57-abc0-4e53-ab0c-913f0b8c8020" class="footnote"> <hr /> <ol></ol> </div>

and corresponding script:

<script type="text/javascript"> $(function () { var footnotes = $('#6c708d57-abc0-4e53-ab0c-913f0b8c8020 ol'); $('a[rel="footnote"]').each(function () { var reference = $(this).text(); var text = $(this).attr('data-text'); var href = $(this).attr('href').substring(1); footnotes.append('<li id="' + href + '">' + text + '</li>'); }); }); </script>

the problem when want reuse same note on several elements, note gets duplicated in bottom section. i'd appear once.

what simplest solution retrieve semantically distinct list of a?

i have looked @ jquery.unique() elements unique far dom concerned.

store notes in hash go - if 1 exists, go on returning in iteration step:

<script type="text/javascript"> $(function () { var footnotes = $('#6c708d57-abc0-4e53-ab0c-913f0b8c8020 ol'); var notesprocessed = {}; $('a[rel="footnote"]').each(function () { var reference = $(this).text(); var text = $(this).attr('data-text'); var href = $(this).attr('href').substring(1); if(notesprocessed[href]) return; footnotes.append('<li id="' + href + '">' + text + '</li>'); notesprocessed[href] = true; }); }); </script>

jquery asp.net-mvc-4

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -