jquery Questions - SnippetGood most recent 30 from http://snippetgood.com 2010-07-29T23:56:45Z http://snippetgood.com/feeds/tag/jquery http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://snippetgood.com/questions/125/how-can-i-find-a-div-in-javascript-or-jquery How can I find a div in javascript or jquery Greg 2009-10-23T16:45:36Z 2010-07-17T05:22:19Z <p>How do I find on my page using javascript or jquery?</p> http://snippetgood.com/questions/95/ie8-window-open-alternative-in-javascript-jquery IE8 window.open alternative in javascript/jquery Greg 2009-10-14T15:55:01Z 2010-06-21T12:18:38Z <p>Is there an alternative to window.open in javascript/jquery? I'm asking because the function doesn't seem to work in IE8 any longer. </p> http://snippetgood.com/questions/33/how-do-you-make-rounded-corners-in-all-browsers How do you make rounded corners in all browsers? binky 2009-10-03T03:05:13Z 2010-02-20T06:31:57Z <p>CSS? JQuery? What's the best and most efficient way to make rounded corners that work in all browsers? I've tried a few and right now I'm making small divs that are positioned negatively outside of the relatively positioned parent divs. Instead of foreground images, I use sprites so the corner divs are less invasive. (ha ha I should give them shorter class names too)</p> <p>since I'm asking for a snippet - I'll leave a snippet of what I do. </p> <pre><code>&lt;div id="container"&gt; &lt;div class="corner-top-left"&gt;&lt;/div&gt;&lt;div class="corner-top-right"&gt;&lt;/div&gt; &lt;div class="corner-bottom-left"&gt;&lt;/div&gt;&lt;div class="corner-bottom-right"&gt;&lt;/div&gt; &lt;/div&gt; #container { display: block; height: 300px; position: relative; width: 500px; } .corner-top-left, .corner-top-right, .corner-bottom-left, .corner-bottom-right { background: url(corner.png) 0 0 no-repeat; display: block; height: 10px; position: absolute; width: 10px; } .corner-top-left { top: -10px; left: -10px;} .corner-top-right { background-position: x x; top: -10px; right: -10px;} .corner-bottom-left { background-position: x x; bottom: -10px; left: -10px;} .corner-bottom-right { background-position: x x; bottom: -10px; right: -10px;} </code></pre> http://snippetgood.com/questions/63/current-year-copyright-line-in-jquery Current Year Copyright Line in JQuery binky 2009-10-11T01:44:54Z 2009-11-22T06:56:42Z <p>I was wondering what ways there are to have the current year in a copyright line. I don't like having to change it manually every year.</p> http://snippetgood.com/questions/129/how-can-i-display-formatted-rss-data-in-a-div How can I display formatted rss data in a DIV OPIEWeb 2009-10-23T19:33:07Z 2009-11-11T13:25:24Z <p>I'd like to display the title and a snippet of the last 2 or 3 entries of an RSS feed on another site. </p> <p>I do not have access to a server-side technology on the receiving page, only Javascript/JQuery. </p> <p>What do I need in order to get that done? </p> http://snippetgood.com/questions/89/if-statements-and-ranges If statements and ranges miss snippet 2009-10-13T17:23:45Z 2009-11-11T04:45:33Z <p>I have a JQuery script that I'm working on and in part of it, I am comparing a value to make sure it is within a specific integer range.</p> <p>This is what my first attempt looks like:</p> <pre><code>if (levelCounter &lt; 0) { levelCounter = 0; } if (levelCounter &gt; maxLevels) { levelCounter = maxLevels;} </code></pre> <p>I'm hoping there's a shorter more efficient way to do this - I can't think of it off the top of my head.</p> http://snippetgood.com/questions/50/how-can-i-make-a-basic-jquery-rotator How can I make a basic jquery rotator? Greg 2009-10-08T22:57:42Z 2009-10-29T17:41:24Z <p>Are there any jquery rotators out there that are both basic and flexible? I've tried a bunch of carousel ones and they are not what I want.</p> <p>It should have pager ability and transitions if possible. Also I need to be able to put text on the images, but if that's not possible I could save the text into the images.</p> http://snippetgood.com/questions/126/add-a-class-to-something-based-on-its-content-in-jquery add a class to something based on its content in jquery? Gwyneth 2009-10-23T16:49:08Z 2009-10-23T16:58:38Z <p>I have a bunch of divs that have the same class on them. They are created dynamically, so I can't assign any further classes to differentiate them. Is there anything I can do to make one have red text for example if it's a certain tag like "photoshop"?</p> http://snippetgood.com/questions/122/jquery-how-can-i-use-show-hide-and-opacity JQuery how can I use show/hide and opacity? miss snippet 2009-10-23T03:51:19Z 2009-10-23T03:51:19Z <p>This goes for all effects except for slideUp/slideDown. </p> <p>If I set opacity for an id/class that I'm manipulating with show/hide or fadeIn/fadeOut, my opacity is set to 1 (100%) instead of whatever I've set it as in the css. Is there any way to override that behaviour? </p> http://snippetgood.com/questions/42/use-jquery-hosted-by-google-or-hosted-by-microsoft Use jQuery hosted by Google or hosted by Microsoft? StopTheSearch.com 2009-10-05T04:50:02Z 2009-10-21T03:31:11Z <p>They both offer jQuery hosting now - which should I use? I'm leaning towards the Microsoft option since they also host the jquery-1.3.2-vsdoc.js file which means I get full Intellisense support in Visual Studio.</p> <p>Thoughts?</p> http://snippetgood.com/questions/115/halloween-ghost-script-count-hidden-divs Halloween Ghost Script: count hidden divs? miss snippet 2009-10-20T02:52:34Z 2009-10-21T00:48:26Z <p>I have a script that I'm working on which is close to functionality sought here: <a href="http://snippetgood.com/questions/48/ninjafy-javascript-halloween-pirates-or-ghosts-or-ninjas" rel="nofollow">http://snippetgood.com/questions/48/ninjafy-javascript-halloween-pirates-or-ghosts-or-ninjas</a> </p> <p>The ghosts appear when you hit more ghosts and disappear when you hover over them or click less ghosts. The functionality I'm looking to add now is to check when you hover on a ghost to see if that was the last ghost showing, and if so, reset the ghosts back to 0. I'm not sure of the best logic to use here: count the hidden divs? </p> <p>Any ideas? Tips on tidying my jquery are also appreciated!</p> <p>The (updated) demo is here: <a href="http://content.snippetgood.com/demos/halloween-ghosts-v1.html" rel="nofollow">http://content.snippetgood.com/demos/halloween-ghosts-v1.html</a></p> <p><strong>CSS</strong></p> <pre><code> body { background-color: #000; color: #fff; font-family: Trebuchet MS; } h1 { color: #fff; } #more-ghosts, #less-ghosts { cursor: pointer; font-size: 20pt; text-decoration: blink; } #ghost-count { font-size: 40pt; } .maximum { color: #b00; } .ghost-1, .ghost-2, .ghost-3, .ghost-4, .ghost-5 { background: url(images/ghosts-ghost-1.png) 0 0 no-repeat; cursor: crosshair; display: none; height: 50px; width: 50px; } </code></pre> <p><strong>HTML</strong></p> <pre><code> &lt;div id="ghosts"&gt; &lt;div class="ghost-1"&gt;&lt;/div&gt;&lt;div class="ghost-1"&gt;&lt;/div&gt;&lt;div class="ghost-1"&gt; &lt;/div&gt;&lt;div class="ghost-1"&gt;&lt;/div&gt; &lt;div class="ghost-2"&gt;&lt;/div&gt;&lt;div class="ghost-2"&gt;&lt;/div&gt;&lt;div class="ghost-2"&gt;&lt;/div&gt;&lt;div class="ghost-2"&gt;&lt;/div&gt; &lt;div class="ghost-3"&gt;&lt;/div&gt;&lt;div class="ghost-3"&gt;&lt;/div&gt;&lt;div class="ghost-3"&gt;&lt;/div&gt;&lt;div class="ghost-3"&gt;&lt;/div&gt; &lt;div class="ghost-4"&gt;&lt;/div&gt;&lt;div class="ghost-4"&gt;&lt;/div&gt;&lt;div class="ghost-4"&gt;&lt;/div&gt;&lt;div class="ghost-4"&gt;&lt;/div&gt;&lt;div class="ghost-4"&gt;&lt;/div&gt; &lt;div class="ghost-5"&gt;&lt;/div&gt;&lt;div class="ghost-5"&gt;&lt;/div&gt;&lt;div class="ghost-5"&gt;&lt;/div&gt;&lt;div class="ghost-5"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="control-panel"&gt; &lt;div id="more-ghosts"&gt; + more ghosts&lt;/div&gt; &lt;div id="ghost-count"&gt; 0&lt;/div&gt; &lt;div id="less-ghosts"&gt; - less ghosts&lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>JQUERY</strong></p> <pre><code>$(function() { var maxGhosts = 5; var docWidth = $(document).width(); var docHeight = $(document).height(); $("#ghosts div").each(function () { var positionLeft = Math.round(Math.random()*(docWidth - $(this).width())); var positionTop = Math.round(Math.random()*(docHeight)); $(this).css("position","absolute").css("top",positionTop+"px").css("left",positionLeft+"px"); }); var ghostCount = 0; $("#more-ghosts").click(function() { if (ghostCount &lt; maxGhosts) { ghostCount++; $(".ghost-"+ghostCount).fadeIn("slow"); if (ghostCount == maxGhosts) { ghostMeter = "MAXIMUM GHOSTS!"; $("#ghost-count").addClass("maximum"); } else { ghostMeter = ghostCount } $("#ghost-count").text(ghostMeter); } }); $("#less-ghosts").click(function() { if (ghostCount &gt; 0){ $(".ghost-"+ghostCount).fadeOut("slow"); ghostCount--; if (ghostCount &lt; maxGhosts) { $("#ghost-count").removeClass("maximum"); } $("#ghost-count").text(ghostCount); } }); $("#ghosts div").hover(function() {$(this).fadeOut("slow"); }); }); </code></pre> http://snippetgood.com/questions/113/add-class-on-hover-wtih-jquery add class on hover wtih jquery Greg 2009-10-19T23:27:22Z 2009-10-19T23:28:57Z <p>I'm stuck on how to add a class on hover and remove it on mouseout.</p> http://snippetgood.com/questions/91/how-can-i-build-a-rotating-tips-feature-using-javascript How can I build a rotating "Tips" feature using Javascript OPIEWeb 2009-10-13T20:42:10Z 2009-10-14T02:32:40Z <p>I'd like to build a Javascript function that can read tips off of an XML or text document and display them randomly. I may up to two on screen at a time and it would be nice if they displayed different tips. The function would only need to change tips on page load and does not need to support async calls. I'm not exactly sure where to start. </p> <p>JQuery is fine as well, although I have no experiance in using it and would rather not have to include multiple libraries. </p> <p>For those that care, this is for a StackExchange site which has some JQuery capabilities baked in. </p> http://snippetgood.com/questions/93/how-can-i-use-jquery-datepicker How can I use jQuery Datepicker? steveT 2009-10-13T23:26:25Z 2009-10-13T23:26:25Z <p>I've seen datepickers for other languages. How could I use jQuery datepicker if I wanted to put a calendar on my website?</p> http://snippetgood.com/questions/90/can-i-use-jquery-to-animate-using-a-class Can I use JQuery to animate using a class? miss snippet 2009-10-13T18:00:48Z 2009-10-13T18:18:07Z <p>I want to use jquery animate to do an animation, but I'm really hoping to define the end result as a class. Is there any way to use animate and addClass together?</p> <p>NB: there would be more to the CSS - it is not a straight show/hide. I don't want to define all the attributes in animate() because it makes it less flexible for people to reuse.</p> <p>ex:</p> <pre><code> .start { display: none; height: 0; width: 0; } .end { display: block; height: 30px; width: 30px; } </code></pre> http://snippetgood.com/questions/73/trigger-event-in-jquery-based-on-whether-div-has-content-or-not Trigger event in JQuery based on whether div has content or not Greg 2009-10-11T03:16:10Z 2009-10-11T03:17:36Z <p>I want to trigger an event in jquery based on whether or not it has content in it. How do I do that?</p> http://snippetgood.com/questions/51/how-can-i-make-a-lightbox-effect-on-pageload How can I make a lightbox effect on pageload? Greg 2009-10-09T00:08:00Z 2009-10-10T18:39:32Z <p>I want to make a popup div appear on pageload with a lightbox type effect - how do I do that?</p> http://snippetgood.com/questions/9/sliding-overlays Sliding Overlays Code Newb 2009-09-30T21:50:12Z 2009-10-09T21:22:37Z <p>I'm looking for a snippet for an div with an image in the background and a translucent overlay that slides up on hover and down on mouse out.</p> http://snippetgood.com/questions/53/how-can-i-use-jquery-animate How can I use jQuery animate()? binky 2009-10-09T04:14:28Z 2009-10-09T04:18:29Z <p>I'd like to use jQuery to do more animation, especially with the nav. Do you have any tips for using jQuery animiate()?</p> http://snippetgood.com/questions/23/styling-community-server-article-pages Styling Community Server Article Pages binky 2009-10-01T17:24:57Z 2009-10-07T16:44:19Z <p>The article pages on Community Server 4.1 get one template and it's hard to do any individual styling to make an article look like it's unique from the other ones. I needed a way to attach an ID or class to the shell of a site or even to the body tag. This is the solution that I came up with.</p> <p><strong>EXPLANATION</strong> </p> <p>This code will let you add a unique class to you website shell. </p> <p>What it does is: </p> <ul> <li>grab the text of the h1</li> <li>nullify all symbols except / and - </li> <li>replace the spaces with dashes.</li> <li>convert all characters to lowercase.</li> </ul> <p>So, if the page is called About Community Server, the website shell div will look like this:</p> <pre><code>&lt;div id="website-shell" class="about-community-server-pg"&gt;&lt;/div&gt; </code></pre> <p><strong><em>caveats</em></strong></p> <p><em>For this to work, you'll need one h1 with the class "content-title" - if you use more than one, you're probably not going to get the class you're expecting.<br /> If you change the h1 text, the class attached to the website shell will also change. However, this isn't for use on normal pages that you can style - only Community Server article pages with limited styling flexibility.</em></p> <p><strong>HTML</strong></p> <pre><code>&lt;div id="website-shell"&gt; &lt;h1 class="content-title"&gt;frequently asked questions&lt;/h1&gt; &lt;/div&gt; </code></pre> <p><strong>JQUERY</strong></p> <pre><code>&lt;script type="text/javascript"&gt; $(function() { var h1Class = $(".content-title").text().replace(/ /g,"-").replace(/[^\w/-]/g, '').toLowerCase(); $("#website-shell").addClass(h1Class+"-pg"); }); &lt;/script&gt; </code></pre> http://snippetgood.com/questions/35/dynamically-change-the-background-colour-of-even-or-odd-rows-in-a-table-zebra-st Dynamically change the background colour of even or odd rows in a table (zebra stripe) Tillimook 2009-10-04T03:25:05Z 2009-10-04T03:30:01Z <p>How can I dynamically change the background colour of even or odd rows in a table? this is also known as zebra striping.</p> http://snippetgood.com/questions/25/add-commas-to-list-items-except-for-last-one-jquery Add Commas to List Items Except for Last One JQuery Code Newb 2009-10-02T14:23:47Z 2009-10-02T15:05:15Z <p>I have a bunch of items that I want to seperate by commas, but this is causing the last item to also have a comma. How do I keep the last item from having a comment?</p> <pre><code>$("#popular-tags li a").append(", "); </code></pre> http://snippetgood.com/questions/21/style-a-form-button-with-css Style a Form Button With CSS Code Newb 2009-10-01T16:14:38Z 2009-10-01T16:16:04Z <p>How can I style a form button or .net control button if I don't have access to the code to insert an image?</p> http://snippetgood.com/questions/18/use-the-latest-jquery-directly-from-google Use the Latest Jquery Directly from Google binky 2009-10-01T15:49:57Z 2009-10-01T15:50:13Z <p>It's really problematic to update files, change version, make sure you got every instance... so I'm looking for a way to add the latest jquery all the time.</p>