1

I want to make a constructor whose instances are jquery objects, so that

var obj = new MyConstructor();
$("body").append(obj); // append instance to html body

how do implement such a constructor ?

3
  • What does MyConstructor do? Commented Apr 21, 2011 at 2:05
  • Should it return an element or a string? Commented Apr 21, 2011 at 2:06
  • @Jason: I think the OP is asking that same question. Commented Apr 21, 2011 at 2:11

1 Answer 1

2

A jQuery object is just a DOM element which has been augmented (by jQuery). What is insufficient about this? Unless you have some other use case in mind, you don't need to do anything fancy with a constructor.

var $obj = $('<div>Foo bar baz</div>');
$('body').append($obj);

// really, all you need is this:
$('body').append('<div>Foo bar baz</div>');
Sign up to request clarification or add additional context in comments.

1 Comment

Gah, thanks for the edit... I should not be writing code this tired.

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.