Javascript examples for jQuery:Variable
Calling a jQuery method named in variable
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> <script type="text/javascript"> $(window).load(function(){// ww w . ja v a2 s. co m var method = 'attr("src")'; console.log((new Function( "return $('img')."+method )())); }); </script> </head> <body> <img src="test.png"> </body> </html>