hackalive Posted March 5, 2012 Share Posted March 5, 2012 Hey guys I am always getting a returned value of "undefined" for the below code, but cant figure out why. <div id="wrapper" title="MEMEME"> <div class="container" onclick="getTitle();"> </div> </div> function getTitle() { var gt= $(this).parent().attr('title'); alert(gt); } Quote Link to comment https://forums.phpfreaks.com/topic/258287-always-undefined/ Share on other sites More sharing options...
kicken Posted March 5, 2012 Share Posted March 5, 2012 inside your getTitle function this is the window object, not your div. You need to pass in your div as a parameter if you want access to it. <div class="container" onclick="getTitle(this);"> function getTitle(div){ //$(div) and so on } Quote Link to comment https://forums.phpfreaks.com/topic/258287-always-undefined/#findComment-1324044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.