jquery - Short If / Else statement in variable equalling "left" or "right" -


tpl = '<li class="left">'; 

i this, if var text contains @tim marshall: or @mark smyth: return class of "right" if doesn't returns value of "left"

i know starting grounds this:

var contains = text. if contains 'this' || 'that' = 'right' : 'left'  tpl = '<li class="' + contains + '">'; 

however i'm not 100% sure how this.

you use string.match() test string so:

var contains = text.match(/(@tim marshall:|@mark smyth:)/) === null ? "left" : "right"; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -