Fuddland

Skip to site navigation

When I wrote the previous entry, I noticed that the link to Daisy’s comment did not necessarily make the comment appear at the top of the page, because there was not enough text below it. In order to make it a little clearer to which comment you’ve just jumped, I knocked together a quick bit of JavaScript which alters the background colour of the relevant comment. [I know others must have done this already, but after four fruitless seconds of googling, I decided it’d be quicker to do it myself.]


<script type="text/javascript">
function highLighter(a, col){
// get the URL of the page
var pageURL = new String(self.location);

// Only carry out the function if the URL contains a #
if (pageURL.indexOf("#")!=-1){
// Split the URL into two strings, before and after the #
var ele_temp = pageURL.split("#");

// We want the string after the #
var ele = ele_temp[1];

// Narrow the selection down further if necessary
if (ele.indexOf(a)!=-1){
// Change the relevant element's background colour
document.getElementById(ele).style.backgroundColor=col;
}
}
}

window.onload = function(){
highLighter("comment_", "#F7B737")
}

</script>

Change comment_ and F7B737 to whatever suit your purposes. If the narrowing-down of the element selection is not required, you just call the function with highLighter("", "#F7B737").

If anyone’s got any suggestions for improvements or refinements, let me know. To see it in action, check out Daisy’s comment again. [If it looks like nothing’s changed, refresh the page to force the browser to update its cache of my scripts file.]

In: Indexed / GoogleAdsense & WWW / Web Design

2004 / 02 / 01 – 01:20

Relative links:


Comments

#1

Lyle | 2004 / 02 / 01 – 10:39

Now that’s geeky… *Grin*

 

Commenting Closed

Commenting on this post is closed. Thanks to all those who left comments. If you'd still like to say something about this entry, feel free to email me.