Websites, SEO and web management, London UK.

SEO

jQuery if empty div

Use jQuery IF statement to find an empty div. Sometimes some dynamically generated elements may appear empty and need different CSS to be applied them, jQuery if empty div, jQuery if no content.

jQuery :empty behaves differently in different browsers, so a solution would be:

<script type="text/javascript">
	$(".myElement").each(function(){
		if($(this).text()=="")$(this).css('background','none');
	})
</script>
################################

Simple jQuery Floater

A simple jQuery floater to display messages or ads. Floats down as the page is being scrolled down. This leans to the left edge of the page and when the window is narrow, covers the content.

Style.

.my-jquery-floater{
	height:244px;
	left:0;
	margin-top:60px;
	position:absolute;
	top:0;
	width:50px;
	z-index:1;
}

Including the jQuery library.

In principle, the first line only is needed. The script chunk loads an alternative jquery.min.js in case Google repository is not available at the moment.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
	!window.jQuery && document.write('<script src="../path/jquery.min.js" type="text\/javascript"><\/script>')
//]]>
</script>

Floater.

Place somewhere after the body tag.

<div class="my-jquery-floater" id="my-jquery-floater">
	SIMPLE JQUERY FLOATER
	<script type="text/javascript">
		$(window).scroll(function floater(){
			$('#my-jquery-floater').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 666});
		});
	</script>
</div>
2011

Web Development - XHTML CSS JavaScript jQuery.