Send this to a friend
1 function getElementsByClassName(node,classname) {
2 if (node.getElementsByClassName) {
3 return node.getElementsByClassName(classname);
4 } else {
5 return (function getElementsByClass(searchClass,node) {
6 if ( node == null )
7 node = document;
8 var classElements = [],
9 els = node.getElementsByTagName("*"),
10 elsLen = els.length,
11 pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"), i, j;
12
13 for (i = 0, j = 0; i < elsLen; i++) {
14 if ( pattern.test(els[i].className) ) {
15 classElements[j] = els[i];
16 j++;
17 }
18 }
19 return classElements;
20 })(classname, node);
21 }
22 }
23
24 var elements = getElementsByClassName(document, "myclass");
function getElementsByClassName(node,classname) {
if (node.getElementsByClassName) {
return node.getElementsByClassName(classname);
} else {
return (function getElementsByClass(searchClass,node) {
if ( node == null )
node = document;
var classElements = [],
els = node.getElementsByTagName("*"),
elsLen = els.length,
pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"), i, j;
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
})(classname, node);
}
}
var elements = getElementsByClassName(document, "myclass");
Send this to a friend
1 var win = window.open(...);
2 if(win == null || typeof(win) == "undefined" || (win == null && win.outerWidth == 0) || (win != null && win.outerHeight == 0) || win.test == "undefined") {
3
4 }
var win = window.open(...);
if(win == null || typeof(win) == "undefined" || (win == null && win.outerWidth == 0) || (win != null && win.outerHeight == 0) || win.test == "undefined") {
}
Send this to a friend
1 function dateValidation() {
2
3 var obj = document.getElementById("my_field");
4 var day = obj.value.split("/")[0];
5
6 var month = obj.value.split("/")[1];
7 var year = obj.value.split("/")[2];
8
9 if ((day<1 || day >31) || (month<1&&month>12)&&(year.length != 4)) {
10 alert("Invalid format");
11 return false;
12 } else {
13
14 var dt = new Date(year, month-1, day);
15 var today = new Date();
16
17 if((dt.getDate() != day) || (dt.getMonth() != month-1) || (dt.getFullYear()!=year) || (dt>today)) {
18 alert("Invalid date");
19 return false;
20 }
21 }
22 }
function dateValidation() {
var obj = document.getElementById("my_field");
var day = obj.value.split("/")[0];
var month = obj.value.split("/")[1];
var year = obj.value.split("/")[2];
if ((day<1 || day >31) || (month<1&&month>12)&&(year.length != 4)) {
alert("Invalid format");
return false;
} else {
var dt = new Date(year, month-1, day);
var today = new Date();
if((dt.getDate() != day) || (dt.getMonth() != month-1) || (dt.getFullYear()!=year) || (dt>today)) {
alert("Invalid date");
return false;
}
}
}
Send this to a friend
1 break
2 case
3 catch
4 continue
5 default
6 delete
7 do
8 else
9 finally
10 for
11 function
12 if
13 in
14 instanceof
15 new
16 return
17 switch
18 this
19 throw
20 try
21 typeof
22 var
23 void
24 while
25 with
26 abstract
27 boolean
28 byte
29 char
30 class
31 const
32 debugger
33 double
34 enum
35 export
36 extends
37 final
38 float
39 goto
40 implements
41 import
42 int
43 interface
44 long
45 native
46 package
47 private
48 protected
49 public
50 short
51 static
52 super
53 synchronized
54 throws
55 transient
56 volatile
break
case
catch
continue
default
delete
do
else
finally
for
function
if
in
instanceof
new
return
switch
this
throw
try
typeof
var
void
while
with
abstract
boolean
byte
char
class
const
debugger
double
enum
export
extends
final
float
goto
implements
import
int
interface
long
native
package
private
protected
public
short
static
super
synchronized
throws
transient
volatile
Send this to a friend
1 <script type="text/javascript" src="http://www.google.com/jsapi"></script>
2 <script type="text/javascript">
3
4 google.load("feeds", "1");
5
6 function initialize() {
7 var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
8 feed.load(function(result) {
9 if (!result.error) {
10 var container = document.getElementById("feed");
11 for (var i = 0; i < result.feed.entries.length; i++) {
12 var entry = result.feed.entries[i];
13 var div = document.createElement("div");
14 div.appendChild(document.createTextNode(entry.title));
15 container.appendChild(div);
16 }
17 }
18 });
19 }
20 google.setOnLoadCallback(initialize);
21
22 </script>
23 <div id="feed"></div>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("feeds", "1");
function initialize() {
var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("feed");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var div = document.createElement("div");
div.appendChild(document.createTextNode(entry.title));
container.appendChild(div);
}
}
});
}
google.setOnLoadCallback(initialize);
</script>
<div id="feed"></div>
Send this to a friend
1 if (navigator.userAgent.match(/iP(ad|hone|od)/i)) {
2
3
4
5 }
if (navigator.userAgent.match(/iP(ad|hone|od)/i)) {
}
Send this to a friend
1 var link_to = function (text, url, options) {
2 var link = document.createElement('a');
3 link.textContent = text;
4 link.setAttribute('href', url);
5
6 for (option in options) {
7 link.setAttribute(option, options[option]);
8 }
9
10 return link;
11 };
12
13 var image_tag = function (alt, src, options) {
14 var image = document.createElement('img');
15 image.setAttribute('alt', alt);
16 image.setAttribute('src', src);
17
18 for (option in options) {
19 image.setAttribute(option, options[option]);
20 }
21
22 return image;
23 };
24
25 link_to("Google", "http://google.com", { id: 321, title: "Google" });
26
27 image_tag("Google", "http://www.google.com/images/logos/ps_logo2.png", { id: "logo", title: "Google's Logo" });
var link_to = function (text, url, options) {
var link = document.createElement('a');
link.textContent = text;
link.setAttribute('href', url);
for (option in options) {
link.setAttribute(option, options[option]);
}
return link;
};
var image_tag = function (alt, src, options) {
var image = document.createElement('img');
image.setAttribute('alt', alt);
image.setAttribute('src', src);
for (option in options) {
image.setAttribute(option, options[option]);
}
return image;
};
link_to("Google", "http://google.com", { id: 321, title: "Google" });
image_tag("Google", "http://www.google.com/images/logos/ps_logo2.png", { id: "logo", title: "Google's Logo" });
Send this to a friend
1 if (/webkit/.test(navigator.userAgent.toLowerCase())) {
2 alert('hello webkit!');
3 }
if (/webkit/.test(navigator.userAgent.toLowerCase())) {
alert('hello webkit!');
}
Send this to a friend
based on http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery version
1 <style>
2 #tooltip {
3 position:absolute;
4 border:1px solid #333;
5 background:#f7f5d1;
6 padding:2px 5px;
7 color:#333;
8 display:none;
9 }
10 </style>
11
12 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
13
14 <script type="text/javascript">
15 $(document).ready(function(){
16 xOffset = 10;
17 yOffset = 20;
18
19 $("a.tooltip").hover(function(e){
20 this.t = this.title;
21 this.title = "";
22 $("body").append("<p id='tooltip'>"+ this.t +"</p>");
23 $("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("fast");
24 }, function(){
25 this.title = this.t;
26 $("#tooltip").remove();
27 });
28
29 $("a.tooltip").mousemove(function(e){
30 $("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px");
31 });
32 });
33 </script>
34
35 <a href="http://cssglobe.com" class="tooltip" title="Web Standards Magazine">Roll over for tooltip</a>
<style>
#tooltip {
position:absolute;
border:1px solid #333;
background:#f7f5d1;
padding:2px 5px;
color:#333;
display:none;
}
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
xOffset = 10;
yOffset = 20;
$("a.tooltip").hover(function(e){
this.t = this.title;
this.title = "";
$("body").append("<p id='tooltip'>"+ this.t +"</p>");
$("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px").fadeIn("fast");
}, function(){
this.title = this.t;
$("#tooltip").remove();
});
$("a.tooltip").mousemove(function(e){
$("#tooltip").css("top",(e.pageY - xOffset) + "px").css("left",(e.pageX + yOffset) + "px");
});
});
</script>
<a href="http://cssglobe.com" class="tooltip" title="Web Standards Magazine">Roll over for tooltip</a>
Send this to a friend
1 $(document).ready(function(){
2
3 $(window).bind("resize", resizeWindow);
4 function resizeWindow( e ) {
5 var newWindowHeight = $(window).height();
6 $("#container").css("min-height", newWindowHeight );
7 }
8
9 });
$(document).ready(function(){
$(window).bind("resize", resizeWindow);
function resizeWindow( e ) {
var newWindowHeight = $(window).height();
$("#container").css("min-height", newWindowHeight );
}
});