User:Proteins/listanchors.js

// // List document anchors, my first JavaScript program

function listAnchors { var temp_anchor; var alert_string; var anchor_index = 0;

alert_string = "This document has " + document.anchors.length + " anchors:\n"; for (anchor_index=0; anchor_index<document.anchors.length; anchor_index++) { temp_anchor = document.anchors[anchor_index]; alert_string += "Name " + anchor_index + ": " + temp_anchor.name + "\n"; }	window.alert(alert_string);

/* Case doesn't matter in getElementsByTagName

alert_string = "This document has " + document.anchors.length + " anchors.\n"; alert_string += "This document has " + document.links.length + " links.\n"; alert_string += "This document has " + document.getElementsByTagName("a").length + " a-tags.\n"; alert_string += "This document has " + document.getElementsByTagName("A").length + " A-tags.\n"; alert_string += "This document has " + document.getElementsByTagName("p").length + " p-tags.\n"; alert_string += "This document has " + document.getElementsByTagName("P").length + " P-tags.\n"; window.alert(alert_string); }

$(function {            mw.util.addPortletLink('p-cactions', 'javascript:listAnchors', 'List anchors', 'ca-listanchors', 'Lists anchors', , ); });

//