Jump to content

$(function(){}??


detestableguy

Recommended Posts

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?

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/206106-function/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/206106-function/#findComment-1078487
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/206106-function/#findComment-1078500
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/206106-function/#findComment-1078511
Share on other sites

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]

Link to comment
https://forums.phpfreaks.com/topic/206106-function/#findComment-1078573
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.