detestableguy Posted June 28, 2010 Share Posted June 28, 2010 I have got a code about rating. My problem is that a link calls javascript in a following way <a href='javascript:;' class='vote_up' id='27'>Vote Up!</a> where the javascript begins in following way $(function(){ $("a.vote_up").click(function(){ //get the id the_id = $(this).attr('id'); ............................ ........... goes on........... } My problem is I want to convert this link in something like "<a href="javascript(rating (id))" /> How can I do this? And please also tell me what does it mean when a function starts with "$" sign? Quote Link to comment https://forums.phpfreaks.com/topic/206106-function/ Share on other sites More sharing options...
trq Posted June 28, 2010 Share Posted June 28, 2010 My problem is I want to convert this link in something like "<a href="javascript(rating (id))" /> Why? The method you are using is much better as it allows you to keep your javascript separate from your markup. And please also tell me what does it mean when a function starts with "$" sign? Nothing in particular. $ is just another variable. In this case it looks like it is the jQuery framework. Quote Link to comment https://forums.phpfreaks.com/topic/206106-function/#findComment-1078487 Share on other sites More sharing options...
ixicoding Posted June 29, 2010 Share Posted June 29, 2010 As far as it's use in this case and in general it seems the dollar sign ($) is used for abbreviating document.GetElementById. In this case: $("a.vote_up").click(function() Would be like writing: document.GetElementById("a.vote_up").click(function() I haven't had much luck using it, but from a bit of googling this is the best answer I came up with back when I was trying to figure out the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/206106-function/#findComment-1078500 Share on other sites More sharing options...
trq Posted June 29, 2010 Share Posted June 29, 2010 As far as it's use in this case and in general it seems the dollar sign ($) is used for abbreviating document.GetElementById. In this case: Nope, in this case (as I said) it is the jQuery object. Quote Link to comment https://forums.phpfreaks.com/topic/206106-function/#findComment-1078505 Share on other sites More sharing options...
ixicoding Posted June 29, 2010 Share Posted June 29, 2010 As far as it's use in this case and in general it seems the dollar sign ($) is used for abbreviating document.GetElementById. In this case: Nope, in this case (as I said) it is the jQuery object. Do explain to us humble muggles, if you have the time. Quote Link to comment https://forums.phpfreaks.com/topic/206106-function/#findComment-1078508 Share on other sites More sharing options...
trq Posted June 29, 2010 Share Posted June 29, 2010 jQuery is a popular Javascript framework (See http://jquery.com). It uses $ to refer to the jQuery object which in turn provides all of jQuery's functionality. var foo = $('#foo'); The variable foo would now hold a reference to the element with an id of 'foo' wrapped within a jQuery object. This allows you to easily use jQueries methods on said element. eg; var foo = $('#foo'); foo.click(function() { alert('You clicked the foo element'); }); Where 'click' is a method of the jQuery object. Quote Link to comment https://forums.phpfreaks.com/topic/206106-function/#findComment-1078511 Share on other sites More sharing options...
ixicoding Posted June 29, 2010 Share Posted June 29, 2010 Alright, that gives me a base for learning more . Thanks for the info. Quote Link to comment https://forums.phpfreaks.com/topic/206106-function/#findComment-1078515 Share on other sites More sharing options...
trq Posted June 29, 2010 Share Posted June 29, 2010 Alright, that gives me a base for learning more . Thanks for the info. It is an awesome framework. I don't do much without it anymore. Quote Link to comment https://forums.phpfreaks.com/topic/206106-function/#findComment-1078516 Share on other sites More sharing options...
ixicoding Posted June 29, 2010 Share Posted June 29, 2010 It seems to streamline quite a bit, thanks again for the info. Quote Link to comment https://forums.phpfreaks.com/topic/206106-function/#findComment-1078528 Share on other sites More sharing options...
detestableguy Posted June 29, 2010 Author Share Posted June 29, 2010 The problem is I am calling multiple javascript files in a .php page. Thats why the script is not working. If I do not import other javascripts, then it works fine. Please help me, tell me how can I call that particular function to run "rating" script? Attached file is that javascript file which is called by the following html code <a href='javascript:;' class='vote_up' id='27'>Vote Up!</a> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/206106-function/#findComment-1078573 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.