patchido Posted February 26, 2013 Share Posted February 26, 2013 i am trying to use javascript through jquery i am trying to follow some tutorials by thenewboston and i cant work it out <p onclick="$(this).hide();"> This is a paragraph </p> that line is supposed to work like that? Quote Link to comment https://forums.phpfreaks.com/topic/274979-new-to-jquery/ Share on other sites More sharing options...
Jessica Posted February 26, 2013 Share Posted February 26, 2013 No, you shouldn't use jQuery inline. You should put your jQuery code within a $(document).ready() function, and give the paragraph an ID or use some other identifier to get to it. Quote Link to comment https://forums.phpfreaks.com/topic/274979-new-to-jquery/#findComment-1415165 Share on other sites More sharing options...
kicken Posted February 26, 2013 Share Posted February 26, 2013 that line is supposed to work like that?That line will work. Just make sure you've included the jQuery library in your page. However, as Jessica said, inline JS code like that is generally not recommended. Quote Link to comment https://forums.phpfreaks.com/topic/274979-new-to-jquery/#findComment-1415174 Share on other sites More sharing options...
patchido Posted February 26, 2013 Author Share Posted February 26, 2013 i've just realized that the tut im looking is using 1.7 jquery and i am using 1.9 if i cahnge the source it works, but not in 1.9, should i use the newest one? Quote Link to comment https://forums.phpfreaks.com/topic/274979-new-to-jquery/#findComment-1415178 Share on other sites More sharing options...
kicken Posted February 26, 2013 Share Posted February 26, 2013 Yes, you should use the newest jQuery. Your sample code is very basic and should work in almost any version. It works just fine in both 1.9 and 1.7 (tested w/ http://jsfiddle.net/MfTUf/) Quote Link to comment https://forums.phpfreaks.com/topic/274979-new-to-jquery/#findComment-1415199 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.