JavaScript Multiple variables in jquery selector multiple variables jquery,multiple var jquery,multiple values jquery,append

I have a code like this

$(".class1 .class2").on('click', function(){
 //Do something        
});

I am trying to somehting like this using variables:

var1=".class1";
var2=".class2"

$(var1 var2).on('click', function(){
   //Do something        
});

I see var1 and var2 are set to right values, but everytime I try to use 2 variables as selector it fails. When I keep the click trigger unchanged and use var1 or var2 elsewhere in the code individually (just var1 or var2 but not in the same selector list) it works. Any tips?

I figure I use var3 concatenate var1 and var2, but I am trying to reduce another variable.

Answer:1

Your sample code has a JavaScript syntax error (there should be a plus sign between var1 and var2, if you intend to concatenate them). However, this would produce a selector ".class1.class2" which is not what you're looking for - this would find an element that has both classes, rather than elements that have either class1 or class2.

So, firstly, you need a plus sign to fix your syntax error. But then you'll need a comma between your class names to select the correct elements.

var1=".class1";
var2=".class2"

// Select ".class1,.class2" (either class1 or class2)
$(var1 + ',' + var2).on('click', function(){
   //Do something        
});
Answer:2

I am trying to figure out how to pass a transclusion down through nested directives and bind to data in the inner-most directive. Think of it like a list type control where you bind it to a list of ...

I am trying to figure out how to pass a transclusion down through nested directives and bind to data in the inner-most directive. Think of it like a list type control where you bind it to a list of ...

I'm trying to create a custom designed share icon for Google Plus that sits in an app that will be inside an iframe. The share should allow for text and an image. I cannot use meta tags as these ...

I'm trying to create a custom designed share icon for Google Plus that sits in an app that will be inside an iframe. The share should allow for text and an image. I cannot use meta tags as these ...

  1. custom share button facebook
  2. custom share button
  3. custom share button twitter
  4. custom share button wordpress
  5. custom share button linkedin
  6. custom facebook share button javascript
  7. custom fb share button
  8. custom whatsapp share button
  9. custom facebook share button code
  10. custom pinterest share button
  11. custom instagram share button
  12. custom twitter share button javascript
  13. custom facebook share button html
  14. create custom share button facebook
  15. custom facebook share button with counter
  16. custom twitter share button popup
  17. custom google share button
  18. javascript custom share button
  19. php custom share button
  20. custom facebook share button stackoverflow

How does one invoke handleButtonPress inside the message map in this example React component? import React, { Component } from 'react'; import {View, Text, TouchableOpacity} from 'react-native'; ...

How does one invoke handleButtonPress inside the message map in this example React component? import React, { Component } from 'react'; import {View, Text, TouchableOpacity} from 'react-native'; ...

I am using the regular expression search code at this link, to allow real time search through a rather large table being populated server-side via php. With a slight twist to the scenario describe in ...

I am using the regular expression search code at this link, to allow real time search through a rather large table being populated server-side via php. With a slight twist to the scenario describe in ...

  1. jquery real time update
  2. jquery real time validation
  3. jquery real time examples
  4. jquery real time clock
  5. jquery real time graph
  6. jquery real time data
  7. jquery real time notification
  8. jquery real time video chat app
  9. jquery real time change event
  10. jquery real time interview questions
  11. jquery real time
  12. jquery real time form validation
  13. jquery real time search
  14. jquery real time input value
  15. jquery real time text change
  16. jquery real time calculation
  17. jquery real time chart
  18. jquery real time update php
  19. jquery real time log viewer
  20. jquery real time chat