Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic hover details with data from text file
    primarykey
    data
    text
    <p>I'm using the jquery hovercard plugin to pull in text from a text file using ajax when a user hovers over a particular text string - this all works great.</p> <p>I've added the functionality to search through the content on page load and add a <code>label</code> class to any matching names - this works great when the name is defined.</p> <p>With help on my <a href="https://stackoverflow.com/questions/13972038/load-text-from-specific-div-in-text-file-using-ajax">previous question</a>; (many thanks @Alex Klock), I have got it so that only one div's text/html is pulled in from the text file on hover - works great when the name is defined. </p> <p>What I need to do now is pull it all together and make it dynamic, so that all names are pulled out of the text file on page load, the correct <code>label</code> class is added to the relevant name/s, and then the correct/corresponding text/html is displayed on hover. </p> <p>Any help would be massively appreciated : )</p> <p><em>//HTML code</em></p> <pre><code>&lt;div id="content"&gt; &lt;p&gt;jQuery by John Resig is a cross-browser JS library designed to simplify the client-side scripting of HTML. It was released in January of 2006 at BarCamp NYC. Used by over 46% of the 10,000 most visited websites, it's the most popular JavaScript library in use today Tim Berners-Lee.&lt;/p&gt; &lt;p&gt;jQuery is free, Tim Berners-Lee open source software, dual-licensed under the MIT License and GNU General Public License, Tim Berners-Lee Version 2.[4] jQuery's syntax is designed to make it easier to navigate a document, select DOM elements, create animations, handle events, and John Resig develop Ajax applications.&lt;/p&gt; &lt;/div&gt; </code></pre> <p><em>//Jquery code</em></p> <pre><code>//based on Highlight words in text with jQuery by (http://www.gotoquiz.com/web-coding/programming/javascript/highlight-words-in-text-with-jquery/) jQuery.fn.addhover = function (str, className) { var regex = new RegExp(str, "gi"); return this.each(function () { $(this).contents().filter(function() { return this.nodeType == 3 &amp;&amp; regex.test(this.nodeValue); }).replaceWith(function() { return (this.nodeValue || "").replace(regex, function(match) { return "&lt;label class=\"" + className + "\" style=\"color:#932121;\"&gt;" + match + "&lt;/label&gt;"; }); }); }); }; $(document).ready(function () { var HTML_FILE_URL = 'helloworld.txt'; $.get(HTML_FILE_URL, function(data) { var fileDom = $(data); fileDom.filter('.contact').each(function() { var savename = $(this).closest(".contact").attr("id"); }); }); $("#content *").addhover("John Resig", "demo-ajax"); var hoverHTMLDemoAjax = '&lt;div class="demo-cb-tweets"&gt;&lt;/div&gt;'; $(".demo-ajax").hovercard({ detailsHTML: hoverHTMLDemoAjax, width: 350, delay: 500, cardImgSrc: 'http://ejohn.org/files/short.sm.jpg', onHoverIn: function () { $.ajax({ url : "helloworld.txt", type: 'GET', dataType: "text", beforeSend: function () { $(".demo-cb-tweets").prepend('&lt;p class="loading-text"&gt;Loading latest tweets...&lt;/p&gt;'); }, success: function (data) { var people = $(data), john = people.filter('#John_Resig'); $(".demo-cb-tweets").empty().append(john); }, complete: function () { $('.loading-text').remove(); } }); } }); }); </code></pre> <p><em>//Helloworld.txt file contents</em></p> <pre><code>&lt;div class="contact" id="John_Resig"&gt; &lt;p&gt;&lt;strong&gt;John_Resig Testing testing testing!&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;And on another line of text : )&lt;/p&gt; &lt;/div&gt; &lt;div class="contact" id="Tim_Berners_Lee"&gt; &lt;p&gt;&lt;strong&gt;Tim_Berners_Lee Testing testing testing!&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;And on another line of text : )&lt;/p&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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