admin管理员组

文章数量:1426072

I want to ask mean of plus operator in this script +i+ in the follow:

i=0;
// next line in scripts write this code :
$('.container[data-id='+i+']').hide(); // +i+ what the meaning of it

Need Help thanks a TON

I want to ask mean of plus operator in this script +i+ in the follow:

i=0;
// next line in scripts write this code :
$('.container[data-id='+i+']').hide(); // +i+ what the meaning of it

Need Help thanks a TON

Share Improve this question asked Dec 13, 2010 at 7:57 Joko WandiroJoko Wandiro 1,9872 gold badges18 silver badges29 bronze badges 3
  • is the above code written by you or its there like that?? – kobe Commented Dec 13, 2010 at 8:03
  • while giving dynamic values in between strings we use somethinglike var finalval= dynamic1 + "test" + dynamic2 – kobe Commented Dec 13, 2010 at 8:04
  • @another programmer write like this and it works, it reference to variable like in the for loop statement – Joko Wandiro Commented Dec 13, 2010 at 8:05
Add a ment  | 

4 Answers 4

Reset to default 4

+ is used to concatenate strings

In this case, it is used to concatenate the value of ibetween .container[data-id= and ]

Assuming that i is storing some value eg 0, then this will be evaluated to

$('.container[data-id=0]').hide();

This will concatenate the value in the variable i with the remaining string.

See Concatenating strings

+ is used for string concantination 

var test= "hello" + "world";// gives helloworld

it is used for adding values also

var c= a+ b// if a=10 and b=20 it gives 30

The + operator in JavaScript is used for both Arithmetic and String operations. If both operands are of Number type, the result is the sum. If either of the operands is not a number, then both will be converted to String and concatenated. It should be used with care.

本文标签: javascriptwhat the meaning of plus operator in this JQUERY scriptsStack Overflow