Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing $(this) in a variable

Tags:

jquery

If I want to save this as a jQuery DOM object and then select it, which method below should I use?

var element = $(this)

And then for selecting

$(element)

Or simply

var element = this

Also, if I want then to concatenate element into a larger selector, is this:

$(element + " .class")

the right way?

like image 920
ilyo Avatar asked May 03 '12 13:05

ilyo


People also ask

What does $() mean in JavaScript?

Usually when you encounter $() , that means the developer is using a javascript library, such as jQuery. The $ symbol is the namespace for those libraries. All the functions they define begin with $. , such as $. get() .

What is $$ in jQuery?

$ is another, which is just an alias to jQuery . $$ is not provided by jQuery. It's provided by other libraries, such as Mootools or Prototype. js. More importantly, $$ is also provided in the console of modern browsers as an alias to document.

How do you keep value after page reloading?

To store the form data in JavaScript localStorage, we'll use the setItem() method. It stores the data in the localStorage object and takes the key and value parameters as input. The parameters can be later used to retrieve the data when the browser reloads the page or a new session is initiated.

How do you make a variable equal another variable in JavaScript?

After a value is assigned to a variable using the assignment operator, you can assign the value of that variable to another variable using the assignment operator. var myVar; myVar = 5; var myNum; myNum = myVar; The above declares a myVar variable with no value, then assigns it the value 5 .


1 Answers

var element = $(this)

Then you can use element instead of $(this). You don't have to insert element into $() anymore.

For example : element.remove() instead of $(this).remove()

like image 163
gabitzish Avatar answered Oct 14 '22 23:10

gabitzish