views:

122

answers:

2

How do I write the following line which is in javascript in jQuery?

var variablename = new functionname('some variable');

This is my js code: var rt = new ResizeableTextbox('myRT');

I need to use this in the following code segment:

 if($(this).text() =='String')
 {
    $("<label id=labelstr"+stringinc+" >"+label+"</label>").appendTo(".menu li");            
    $("<input id=inputstr"+stringinc+" type= 'text' ></input>").appendTo(".menu li");              
    //in place of this I need that javascript code.
 }

How do I do that? The function Resizeable is defined in a separate js file. Please help me out.

+8  A: 

I don't think you would... that is fundamental JavaScript syntax. jQuery adds abstraction and utilities etc, but doesn't rewrite the core parts of the language.

Here is an example of JavaScript code to jQuery

Plain Ol' JavaScript

var myForm = document.getElementById('myForm');

jQuery

var myForm = $('#myForm');

These 2 lines essentially do the same thing, dimension a variable titled 'myForm' which contains a pointer (is that the right word?) to the element with an id of myForm. Benefits of using jQuery in this example are more concise syntax, and the ability to use a selector system you should already know, CSS.

alex
plus uno senor :)
Paolo Bergantino
This is my js code: var rt = new ResizeableTextbox('myRT');I need to use this in the following code segment: if($(this).text() =='String') { $("<label id=labelstr"+stringinc+" >"+label+"</label>").appendTo(".menu li"); $("<input id=inputstr"+stringinc+" type= 'text' ></input>").appendTo(".menu li"); //in place of this I need that javascript code.How do I do that? The function Resizeable is defined in a separate js file. Please help me out. }
Angeline Aarthi
@Angeline: Edit the question to reflect what you are actually trying to accomplish and I'm sure someone will be able to help you.
Grant Wagner
A: 

As long as the JavaScript file which defines the ResizeableTextbox function is included in the <head> section of the page, the ResizeableTextbox function can be called anywhere including within your if statement... You probably need to edit your question to describe in more detail what you're trying to do and what's happening instead, because from what you've explained it should work fine.

Josh