jquery Questions - SnippetGoodmost recent 30 from http://snippetgood.com2010-07-29T23:56:45Zhttp://snippetgood.com/feeds/tag/jqueryhttp://www.creativecommons.org/licenses/by-nc/2.5/rdfhttp://snippetgood.com/questions/125/how-can-i-find-a-div-in-javascript-or-jqueryHow can I find a div in javascript or jqueryGreg2009-10-23T16:45:36Z2010-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-jqueryIE8 window.open alternative in javascript/jqueryGreg2009-10-14T15:55:01Z2010-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-browsersHow do you make rounded corners in all browsers? binky2009-10-03T03:05:13Z2010-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><div id="container">
<div class="corner-top-left"></div><div class="corner-top-right"></div>
<div class="corner-bottom-left"></div><div class="corner-bottom-right"></div>
</div>
#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-jqueryCurrent Year Copyright Line in JQuerybinky2009-10-11T01:44:54Z2009-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-divHow can I display formatted rss data in a DIVOPIEWeb2009-10-23T19:33:07Z2009-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-rangesIf statements and ranges miss snippet2009-10-13T17:23:45Z2009-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 < 0) { levelCounter = 0; }
if (levelCounter > 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-rotatorHow can I make a basic jquery rotator?Greg2009-10-08T22:57:42Z2009-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-jqueryadd a class to something based on its content in jquery?Gwyneth2009-10-23T16:49:08Z2009-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-opacityJQuery how can I use show/hide and opacity?miss snippet2009-10-23T03:51:19Z2009-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-microsoftUse jQuery hosted by Google or hosted by Microsoft?StopTheSearch.com2009-10-05T04:50:02Z2009-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-divsHalloween Ghost Script: count hidden divs?miss snippet2009-10-20T02:52:34Z2009-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> <div id="ghosts">
<div class="ghost-1"></div><div class="ghost-1"></div><div class="ghost-1"> </div><div class="ghost-1"></div>
<div class="ghost-2"></div><div class="ghost-2"></div><div class="ghost-2"></div><div class="ghost-2"></div>
<div class="ghost-3"></div><div class="ghost-3"></div><div class="ghost-3"></div><div class="ghost-3"></div>
<div class="ghost-4"></div><div class="ghost-4"></div><div class="ghost-4"></div><div class="ghost-4"></div><div class="ghost-4"></div>
<div class="ghost-5"></div><div class="ghost-5"></div><div class="ghost-5"></div><div class="ghost-5"></div>
</div>
<div id="control-panel">
<div id="more-ghosts">
+ more ghosts</div>
<div id="ghost-count">
0</div>
<div id="less-ghosts">
- less ghosts</div>
</div>
</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 < 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 > 0){
$(".ghost-"+ghostCount).fadeOut("slow");
ghostCount--;
if (ghostCount < 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-jqueryadd class on hover wtih jqueryGreg2009-10-19T23:27:22Z2009-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-javascriptHow can I build a rotating "Tips" feature using JavascriptOPIEWeb2009-10-13T20:42:10Z2009-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-datepickerHow can I use jQuery Datepicker?steveT2009-10-13T23:26:25Z2009-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-classCan I use JQuery to animate using a class?miss snippet2009-10-13T18:00:48Z2009-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-notTrigger event in JQuery based on whether div has content or not Greg2009-10-11T03:16:10Z2009-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-pageloadHow can I make a lightbox effect on pageload?Greg2009-10-09T00:08:00Z2009-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-overlaysSliding OverlaysCode Newb2009-09-30T21:50:12Z2009-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-animateHow can I use jQuery animate()?binky2009-10-09T04:14:28Z2009-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-pagesStyling Community Server Article Pagesbinky2009-10-01T17:24:57Z2009-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><div id="website-shell" class="about-community-server-pg"></div>
</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><div id="website-shell">
<h1 class="content-title">frequently asked questions</h1>
</div>
</code></pre>
<p><strong>JQUERY</strong></p>
<pre><code><script type="text/javascript">
$(function() {
var h1Class = $(".content-title").text().replace(/ /g,"-").replace(/[^\w/-]/g, '').toLowerCase();
$("#website-shell").addClass(h1Class+"-pg");
});
</script>
</code></pre>
http://snippetgood.com/questions/35/dynamically-change-the-background-colour-of-even-or-odd-rows-in-a-table-zebra-stDynamically change the background colour of even or odd rows in a table (zebra stripe)Tillimook2009-10-04T03:25:05Z2009-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-jqueryAdd Commas to List Items Except for Last One JQueryCode Newb2009-10-02T14:23:47Z2009-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-cssStyle a Form Button With CSSCode Newb2009-10-01T16:14:38Z2009-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-googleUse the Latest Jquery Directly from Googlebinky2009-10-01T15:49:57Z2009-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>