views:

181

answers:

1
function loadTextboxes()
{
    var textareas = document.getElementsByTagName('textarea');

    for(var i=0; i < textareas.length; i++)
    {
        if (textareas.item(i).className == "richtextbox")
        {
            richtextbox(textareas.item(i));
        }
    }
}

//window.attachEvent('onload',loadTextboxes);

$(document).ready(function() {
    //loadTextboxes(); // works ...
    $('.richtextbox').each(richtextbox(this));
});

A JavaScript function searches for textarea with class "richtextbox" and calls another function (not posted here) ... tried to do this with jQuery - does not work :-(

+2  A: 

The problem is this line:

$('.richtextbox').each(richtextbox(this));

means you call richtextbox(this) and pass it's return value into each(). That won't work unless the function returns a function.

What I suspect you mean is:

$(function() {
  $("textarea.richtextbox").each(function() {
    richtextbox(this);
  });
});

That's the correct way to pass a named function as a parameter.

Ideally, this would be assumed by the function rather than passed in as an argument, which would allow you to shorten the code to:

$(function() {
  $("textarea.richtextbox").each(richtextbox);
});
cletus