jQuery: Quick question. How to select string variable?

Posted by user317563 on Stack Overflow See other posts from Stack Overflow or by user317563
Published on 2010-05-12T12:44:55Z Indexed on 2010/05/12 13:14 UTC
Read the original article Hit count: 134

Filed under:
|
|

Hello world,

EDIT: I would like to avoid doing something like this:

var str = 'Hello'; 
if ( str == 'Hello') { 
    alert(str); 
} 

I would rather do:

var str = 'Hello'; 
$(str).filter(':contains("Hello")').each(function(){ 
    alert(this) 
});

I've tried a lot of things:

$(str).text().method1().method2().method3();
$(str).val().method1().method2().method3();
$(str).contents().method1().method2().method3();

Nothing worked. Is it possible to do this?

Thank you for your time.

Kind regards,
Marius

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about string