0
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 :-(

1 Answer 1

3

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);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.