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? 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. 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. 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? 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/) Link to comment https://forums.phpfreaks.com/topic/274979-new-to-jquery/#findComment-1415199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.