This works great. One more thing: when I click a link with onclick event it will first preform javascript action and then go to the url. How do I prevent the second step - disable the link so that it wouldn't go to that url after the click? (in current situation using ajax has no benefit).
Thanks again! On Feb 12, 11:25 pm, James <james.gp....@gmail.com> wrote: > $(this) will refer to the one that was clicked on. > > $(document).ready(function() { > $("a.rate").click(function () { > alert($(this).attr('href')); > }); > > }); > > On Feb 12, 12:20 pm, introvert <aljaz.faj...@gmail.com> wrote: > > > But in this case how can I read url (a href) from the a tag for each? > > > On Feb 12, 11:17 pm, James <james.gp....@gmail.com> wrote: > > > > Personally, it's easier to use just a class. It will account for all > > > <a> with class "rate". > > > > <script> > > > $(document).ready(function() { > > > $("a.rate").click(function () { //ajax call });}); > > > > </script> > > > > <a id="rate1" href="#" class="rate up">rate up</a> > > > <a id="rate2" href="#" class="rate up">rate up</a> > > > > On Feb 12, 12:08 pm, introvert <aljaz.faj...@gmail.com> wrote: > > > > > Hello. > > > > > I'm working on a simple thumbs up/down functionality with javascript > > > > (jquery). I have list of entries which can be rated up or down and > > > > this has to be done with ajax. > > > > > I came to a design consideration problem as I dont have many > > > > experience with javascript programming: > > > > > How should I process all links inside a html file so that it would set > > > > onClick event on links and this would call a function that would > > > > preform certain http request. > > > > > Should I give each link an unique id e.g. "rating12" and then set > > > > onclick action for each of the elements so that it would look > > > > something like: > > > > > <script> > > > > $(document).ready(function() { > > > > $("a#rate1").click(function () { //ajax call });}); </script> > > > > > <a id="rate1" href="#" class="rate up">rate up</a> > > > > > <script> > > > > $(document).ready(function() { > > > > $("a#rate2").click(function () { //ajax call });}); </script> > > > > > <a id="rate2" href="#" class="rate up">rate up</a> > > > > > etc.. > > > > > or would it be better to make jquery find each class 'rate' and read a > > > > href from each (with one block code) so that also users with no > > > > javascript could face normal functionality (without ajax) or is there > > > > any better solution/approach for this? > > > > > Whats the best way to deal with this? > > > > > Many thanks in advance!