Loading jQuery

Load with Google API

<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
    google.load("jquery", "1.2.6");
</script>
<script type="text/javascript" src="js/example.js"></script>

Direct Link to Google

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'></script>

Check if loaded, only load if unloaded

var jQueryScriptOutputted = false;
function initJQuery() {

   //if the jQuery object 
Avatar of Chris Coyier
Chris Coyier on

Check if Website is Available

Performs a cURL-Request to check, if a website exists / is online

Technique #1

<?php

       if (isDomainAvailible('https://css-tricks.com'))
       {
               echo "Up and running!";
       }
       else
       {
               echo "Woops, nothing found there.";
       }

       //returns true, if domain is availible, false if not
       
Avatar of Chris Coyier
Chris Coyier on (Updated on )

Display Latest FeedBurner Post

This snippet will display the latest post in a specified FeedBurner feed. Just set the URL to your desired FeedBurner feed.

$(document).ready(function(){
       $.ajax({
               type: "GET",
               url: "http://feeds.feedburner.com/examplefeed",
               success: function(data){
                       $("#date").text($(data).find("item:first>pubDate:first").text());
                       $("#title").html("<a href='"+$(data).find("item:first>link:first").text()+"'>"+$(data).find("item:first>title:first").text()+"</a>");
                       $("#description").html($(data).find("item:first>description:first").text());
               }
       });
});

This example assumes that …

Avatar of Chris Coyier
Chris Coyier on

Crop Image

Displays a selected chunk of an image. In the example provided, the upper left 100px x 100px are shown.

<?php

$filename= "test.jpg";
list($w, $h, $type, $attr) = getimagesize($filename);
$src_im = imagecreatefromjpeg($filename);

$src_x = '0';   // begin x
$src_y = '0';   
Avatar of Chris Coyier
Chris Coyier on

Find All Links on a Page

Here’s the basic principal behind spiders.

$html = file_get_contents('http://www.example.com');

$dom = new DOMDocument();
@$dom->loadHTML($html);

// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");

for ($i = 0; $i < $hrefs->length; $i++) {
       $href = $hrefs->item($i);
       
Avatar of Chris Coyier
Chris Coyier on

Remove Dotted Link Borders

Dotted borders around links are an accessibility feature most browsers have by default. It’s for users who must or choose to navigate by keyboard, there is a visual style applied to those links when “tabbed” to. These borders also show …

Avatar of Chris Coyier
Chris Coyier on (Updated on )

CSS Diagnostics

Find mistakes in HTML and highlight the crap out of them.

/* Empty Elements */
div:empty, span:empty, li:empty, p:empty, td:empty, th:empty
{ padding: 20px; border: 5px dotted yellow !important; }

/* Empty Attributes */
*[alt=""], *[title=""], *[class=""], *[id=""], a[href=""], a[href="#"]
Avatar of Chris Coyier
Chris Coyier on (Updated on )

Image Preloader

Very easy way to preload images which are needed later (e.g. when a hover is performed)

$.preloadImages = function() {
  for (var i = 0; i < arguments.length; i++) {
    $("<img />").attr("src", arguments[i]);
  }
}

$.preloadImages("hoverimage1.jpg","hoverimage2.jpg");
Avatar of Chris Coyier
Chris Coyier on (Updated on )