What I was trying to do here was to make a mootools example in jQuery. In mootools, all you need is:
if(txt.val().contains('hello')) txt.trigger('burn', 'hello world!'); Therefore I was looking for a jQuery way to do it but contains() doesn't work as expected. :( On Aug 27, 3:39 pm, Klaus Hartl <[EMAIL PROTECTED]> wrote: > MrNase wrote: > >> $('#myTextarea').attr('val').indexOf('hello') != -1 > > >> --Klaus > > > $('#myTextarea').val().indexOf('hello') != -1 > > > works. Thanks! :) > > > Now, when I extend my code it doesn't work anymore. > > > if ($('#myTextarea').val().indexOf('hello') != -1) { > > log.empty().html('test'); > > } > > else if ($('#myTextarea').val().indexOf('moo') > > != -1) { > > log.empty().html('test2'); > > } > > > typing in 'moo' works, the log layer get's filled with 'test2'. > > typing in 'moo hello' also works, the log layer get's filled with > > 'test'. > > typing in 'moo hello moo' should produce 'test2' but it just does > > nothing. :( > > That is correct. indexOf works by exact matching, thus "moo hello moo" > may not match and nothing gets logged, both the if and the else > condition are false. > > You may have to use regular expressions for a bit more flexibility. > > --Klaus