J
Jake Barnes
What am I missing? I feel like I've done this before and it's always
been easy, and now I can't get it to work. I want to get every link on
the page that has the CSS class "more", and then assign a function to
it. The function is suppose to resize a div. I simply need to get the
id of the link into this function, but it's blank. What am I doing
wrong? The first alert(), below, has the id, but when the page loads
and click the link, the alert is blank.
Using Simon Wilson's addLoadEvent function.
addLoadEvent(function() {
// 10-07-07 - the designer wants to fit a lot of content onto the
profile.php page.
// She intends for each section to have a small box (I mean a div)
and when
// these boxes fill up, the PHP code will ensure a "more" button
appears at the
// end. All these divs have a fixed height assigned by the CSS, but
when the
// "more" button is clicked, the div should have height:auto, and an
AJAX
// call should fill it. The "more" buttons will all have a class of
"more",
// and their rel attributes will indicate which div we need to resize
and fill.
var arrayOfAllLinksWithTheClassOfMore = getElementsByClass("more");
for (var i=0; i < arrayOfAllLinksWithTheClassOfMore.length; i++) {
var referenceToALinkWhichHasTheClassOfMore =
arrayOfAllLinksWithTheClassOfMore;
var idOfLinkMakingThisCall =
referenceToALinkWhichHasTheClassOfMore.id;
alert(idOfLinkMakingThisCall );
var functionToHappen = function() {
var thisLinkId = idOfLinkMakingThisCall;
alert(thisLinkId);
expandThisDivWithContent(thisLinkId);
return false;
}
if (document.getElementById(idOfLinkMakingThisCall)) {
document.getElementById(idOfLinkMakingThisCall).onclick =
function() {
functionToHappen();
}
}
}
});
been easy, and now I can't get it to work. I want to get every link on
the page that has the CSS class "more", and then assign a function to
it. The function is suppose to resize a div. I simply need to get the
id of the link into this function, but it's blank. What am I doing
wrong? The first alert(), below, has the id, but when the page loads
and click the link, the alert is blank.
Using Simon Wilson's addLoadEvent function.
addLoadEvent(function() {
// 10-07-07 - the designer wants to fit a lot of content onto the
profile.php page.
// She intends for each section to have a small box (I mean a div)
and when
// these boxes fill up, the PHP code will ensure a "more" button
appears at the
// end. All these divs have a fixed height assigned by the CSS, but
when the
// "more" button is clicked, the div should have height:auto, and an
AJAX
// call should fill it. The "more" buttons will all have a class of
"more",
// and their rel attributes will indicate which div we need to resize
and fill.
var arrayOfAllLinksWithTheClassOfMore = getElementsByClass("more");
for (var i=0; i < arrayOfAllLinksWithTheClassOfMore.length; i++) {
var referenceToALinkWhichHasTheClassOfMore =
arrayOfAllLinksWithTheClassOfMore;
var idOfLinkMakingThisCall =
referenceToALinkWhichHasTheClassOfMore.id;
alert(idOfLinkMakingThisCall );
var functionToHappen = function() {
var thisLinkId = idOfLinkMakingThisCall;
alert(thisLinkId);
expandThisDivWithContent(thisLinkId);
return false;
}
if (document.getElementById(idOfLinkMakingThisCall)) {
document.getElementById(idOfLinkMakingThisCall).onclick =
function() {
functionToHappen();
}
}
}
});