Greatly appreciated! And yes, I had used "append" instead of
"appendChild" accidently.
I had worked out another solution but I like yours better. Mine was:
function getPixel() {
if(!$('trackingPixel')) {
var thisPixel = document.createElement('img');
thisPixel.src = "http://www.mysource.com/img/
trackingPixel.gif";
thisPixel.id = "trackingPixel";
$('myTrackerDiv').appendChild(thisPixel);
}
}
On Jan 8, 11:10 am, "T.J. Crowder" <[email protected]> wrote:
> Hi,
>
> > Can anyone help?
>
> Well, you haven't actually said what's wrong :-), but I'm guessing the
> code is failing or you're not seeing the pixel get loaded or
> something.
>
> I think you probably meant "appendChild", rather than "append".
>
> FWIW, if myTrackerDiv only ever contains this pixel, you could also do
> this:
>
> function getPixel() {
> var div;
>
> div = $('myTrackerDiv');
> if (!div.firstChild) {
> div.update("<img src='http://www.mysource.com/img/
> trackingPixel.gif' />");
> }
>
> }
>
> ...which has the advantage of being brief and fairly clear. Perhaps
> surprisingly, most browsers parse HTML and create elements internally
> much faster than they create elements when you do it via their
> external DOM interface. (Just be sure that the div starts out
> completely empty, including no text nodes consisting of whitespace --
> "<div id='myTrackerDiv'></div>", for instance, would be fine, but not
> if the "</div>" part were on a separate line -- because then
> div.firstChild would be a text node consisting of that newline. Or go
> back to using an ID on the tracking pixel, if you prefer.)
>
> HTH,
> --
> T.J. Crowder
> tj / crowder software / com
> Independent Software Engineer, consulting services available
>
> On Jan 8, 3:05 pm, cstahl <[email protected]> wrote:
>
> > I'm using prototype.js and writing a small script that will load a
> > tracking pixel to a webpage when a download link is clicked. The page
> > contains a div:
> > <div id="myTrackerDiv"></div>
> > which is where the tracking pixel will be loaded.
>
> > My function is:
>
> > function getPixel() {
> > if(!$('trackingPixel')) {
> > var thisPixel = new Element('img',
> > {src:"http://www.mysource.com/img/
> > trackingPixel.gif", id:"trackingPixel"});
> > $('myTrackerDiv').append(thisPixel);
> > }
> > return false;}
>
> > which looks for an existing trackingPixel ID and if it doesn't find
> > it, it creates one.
>
> > Can anyone help? I know I'm making some bonehead mistake but I'm kind
> > of beat from banging my head in about this one.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---