Delete a tag in Javascript
October 9, 2008 on 4:42 pm | In Javascript | No CommentsI use with with AJAX library to completely remove a DIV tag ( or whatever )
function removeTag(tag){
field = document.getElementById(tag);
field.parentNode.removeChild(field);
}
function removeAllChildren(field){
if ( field.hasChildNodes() )
{
while ( field.childNodes.length >= 1 )
{
removeAllChildren(field.firstChild);
field.removeChild(field.firstChild);
}
}
}
Ajax wrapper class
April 22, 2008 on 7:22 pm | In Javascript | No CommentsI’m not really a big fan of “AJAX” ( yes, I put it in quotes ). To be honest, I’ve being doing AJAX type stuff since the dawn of Javscript and IFRAMES, but now it has a name and everyone is using it. My pet hate is AJAX for the sake of AJAX, reloading 5mb of data when a simple page refresh will do.
Saying all that, what AJAX I do now, I do with this great wrapper class
http://www.cmarshall.net/MySoftware/ajax/
Works like a charm and really simple to impliment. If I get the time, I’ll add in some very simple PHP examples on how to make re-usable AJAX type code for populating lists etc.
Handling bookmarks / named anchors in an IFRAME
February 14, 2008 on 7:48 pm | In Javascript | No CommentsSo, you are using IFRAMES, good on you. You have a nice document with lots of names anchors, but you find when you click on the bookmark link, the whole window, parent and all, scrolls into view. Pain in the ass. To get around it, use Javascript as such …
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | function findPosY(obj) { var curtop = 0; if(obj.offsetParent) while(1) { curtop += obj.offsetTop; if(!obj.offsetParent)break; obj = obj.offsetParent; } else if(obj.y) curtop += obj.y; return curtop; } function scroll(element){ p = findPosY(document.getElementById(element)); window.scrollBy(0,p); } |
The findPosY is not my code, sorry, cant remember the original author - if I find you I will credit you.
In your HTML use
<a href="javascript:scroll('A');">A
and for the named anchor use any tag and add the ID for the link, ie
<h3 id="A">A
Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^