Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery: Grabbing text() from clicked object
    primarykey
    data
    text
    <p>I know there are a lot of questions similar to this one already out there but none of them seemed to be the same as my current issue (if so sorry for the repeat).</p> <p>What I am trying to create here is a script that will; upon clicking of a link, take the link name and type and find it in the folder. Then once it has been located add it into the DOM inside the specific container (#content in our case).</p> <p>jQuery doesn't seem to want to grab text from an even.target (see code). I'm still learning jQuery so this may seem stupid and elementary to you so please be nice/patient.</p> <p>CODE:</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;Matt Elliott \\ Web Development \\ Video Production&lt;/title&gt; &lt;link rel="stylesheet" href="main.css" media="screen" type="text/css"&gt; &lt;script type="text/javascript" src="jquery-1.4.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery-ui-1.8.4.custom.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { //init vars var adMenu = $('#adMenu'); var webMenu = $('#webMenu'); var videoMenu = $('#videoMenu'); var ad_btn = $('#adToggle'); var web_btn = $('#webToggle'); var video_btn = $('#videoToggle'); var nav = $('nav'); //init settings adMenu.css({'opacity' : '0.0', 'visibility' : 'hidden'}); webMenu.css({'opacity' : '0.0', 'visibility' : 'hidden'}); videoMenu.css({'opacity' : '0.0', 'visibility' : 'hidden'}); //-------------------------------FUNCTIONS------------------------------\\ //event listeners $('#main li, #prevContent, #nextContent').mouseover(function() { $(this).animate({'backgroundColor' : '#F90'}, 1000, 'easeOutElastic'); }); $('#main li, #prevContent, #nextContent').mouseleave(function() { $(this).animate({'backgroundColor' : '#000'}, 300, 'easeInElastic'); }); ad_btn.click(function() { if(videoMenu.css("opacity") == 1.0) { videoMenu.animate({opacity: 0.0}, 500); video_btn.removeClass('selected'); } else if(webMenu.css("opacity") == 1.0) { webMenu.animate({opacity: 0.0}, 500).removeClass('selected'); web_btn.removeClass('selected'); } adMenu.css({'visibility' : 'visible'}); adMenu.animate({opacity: 1.0}, 2000); ad_btn.addClass('selected'); ad_btn.unbind('mouseleave'); }); web_btn.click(function() { if(adMenu.css("opacity") == 1.0) { adMenu.animate({opacity: 0.0}, 500).removeClass('selected'); } else if(videoMenu.css("opacity") == 1.0) { videoMenu.animate({opacity: 0.0}, 500).removeClass('selected'); } webMenu.css({'visibility' : 'visible'}); webMenu.animate({opacity: 1.0}, 2000); web_btn.addClass('selected'); }); video_btn.click(function() { if(adMenu.css("opacity") == 1.0) { adMenu.animate({opacity: 0.0}, 500).removeClass('selected'); } else if(webMenu.css("opacity") == 1.0) { webMenu.animate({opacity: 0.0}, 500).removeClass('selected'); } videoMenu.css({'visibility' : 'visible'}); videoMenu.animate({opacity: 1.0}, 2000); video_btn.addClass('selected'); }); adMenu.click(function() { adMenu.animate({opacity: 0.0}, 200, function() { adMenu.css({'visibility' : 'hidden'}); ad_btn.removeClass('selected'); ad_btn.animate({'backgroundColor' : '#000'}, 300, 'easeInElastic'); ad_btn.mouseleave(function() { $(this).animate({'backgroundColor' : '#000'}, 300, 'easeInElastic'); }); }); }); webMenu.click(function() { webMenu.animate({opacity: 0.0}, 200, function() { webMenu.css({'visibility' : 'hidden'}); web_btn.removeClass('selected'); web_btn.animate({'backgroundColor' : '#000'}, 300, 'easeInElastic'); web_btn.mouseleave(function() { $(this).animate({'backgroundColor' : '#000'}, 300, 'easeInElastic'); }); }) }); videoMenu.click(function() { videoMenu.animate({opacity: 0.0}, 200, function() { videoMenu.css({'visibility' : 'hidden'}); video_btn.removeClass('selected'); video_btn.animate({'backgroundColor' : '#000'}, 300, 'easeInElastic'); video_btn.mouseleave(function() { $(this).animate({'backgroundColor' : '#000'}, 300, 'easeInElastic'); }); }); }); }); function getThis(event,type) { string = $(event.target).text(); filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g,''); if(type == 'jpg') { $('#content').append('&lt;img src="_work/ads/' + filename + '.jpg" /&gt;'); } else if(type == 'swf') { $('#content').append('&lt;embed src="_work/ads/' + filename + '.swf" /&gt;'); } } &lt;/script&gt; &lt;script type="text/javascript"&gt; document.createElement('header'); document.createElement('nav'); document.createElement('article'); document.createElement('section'); document.createElement('footer'); document.createElement('canvas'); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;header&gt; &lt;h1&gt;mattelliott.it&lt;/h1&gt; &lt;nav&gt; &lt;ul id="main"&gt; &lt;li id="adToggle"&gt;&lt;h2&gt;ads&lt;/h2&gt;&lt;/li&gt; &lt;li id="webToggle"&gt;&lt;h2&gt;web&lt;/h2&gt;&lt;/li&gt; &lt;li id="videoToggle"&gt;&lt;h2&gt;video&lt;/h2&gt;&lt;/li&gt; &lt;li&gt;&lt;h2&gt;contact&lt;/h2&gt;&lt;/li&gt; &lt;/ul&gt; &lt;!-- menu divs to fade in --&gt; &lt;div id="adMenu"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="javascript:getThis('jpg');"&gt;bing&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;emirates airlines&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;fast forward&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;prosche&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="webMenu"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;kashmere&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;christopher stewart&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;the gel lab&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;erin foote&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;cicis pizza&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;pepsi natural&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;totally rad&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="videoMenu"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;pepsi natural&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;chasing numbers trailer&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;gel lab shred session&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/nav&gt; &lt;/header&gt; &lt;div id="wrapper"&gt; &lt;section id="content"&gt; &lt;!-- &lt;img src="_work/ads/bing.jpg" /&gt; --&gt; &lt;div id="contentControl"&gt; &lt;a id="prevContent" href="#"&gt;&lt;/a&gt; &lt;a id="nextContent" href="#"&gt;&lt;/a&gt; &lt;/div&gt; &lt;/section&gt; &lt;/div&gt; </code></pre> <p> </p> <p>I don't seem to get any errors though; which is weird. Thanks for all and any help.</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.
    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