Archive for June, 2010

jQuery replace all img tags with certain source…

Monday, June 7th, 2010

$(‘img’).each(function(){
var t=$(this);
var src1 = t.attr(‘src’);
var newSrc = “images/play2.png”;
if(src1 == “images/play.png”)
{
$(this).attr(‘src’, newSrc);
}
});

JavaScript URL parse to load multiple versions

Monday, June 7th, 2010

<script type=”text/javascript” src=”js/jquery-1.3.2.min.js”></script>

<script>
$(document).ready(function() {

<!– Version requested START –>
if (location.search != “”)
{
x = location.search.substr(1).split(“;”)
for (var i=0; i<x.length; i++)
{
y = x[i].split(“=”);
//alert(y[0] + ” ” + y[1])

// Version 2 (/?version=2)
if( y[1] == 2 ){
// do things
}

// Version 3 (/?version=3)
if( y[1] == 3 ){
// do things
}
}
}
<!– Version requested END –>

jQuery .css background-image / .attr src examples

Monday, June 7th, 2010

$(“body”).css(“background-image”, “url(images/bg2.jpg)”);
$(“#header”).css(“background-image”, “url(images/bg-header2.png)”);
$(“#browse”).css(“background-image”, “url(images/bg-browse2.png)”);
$(“#paginate-slider2”).css(“background-image”, “url(images/bg-slide-thumbs2.jpg)”);
$(“#slides”).css(“background-image”, “url(images/bg-slides2.png)”);
$(“#ST-now”).css(“background-image”, “url(images/bg-STnow2.png)”);
$(“#searchBox”).attr(“src”, “images/search-box2.jpg”);
$(“#keywordsBox”).attr(“src”, “images/keywords2.jpg”);
$(“#inBox”).attr(“src”, “images/products2.jpg”);

jQuery add stylesheet dynamically

Monday, June 7th, 2010

within some logic, a function, elsewhere :

var link = $(“<link>”);
link.attr({
type: ‘text/css’,
rel: ‘stylesheet’,
href: ‘css/contentslider2.css’
});
$(“head”).append( link );