62961

jquery problem?

i have this jquery problems i have had for days, im so new to this, so excuse my dumbness in this subject. thanks :))

html code:

<ul class="statuses"> <li id="set_23" class="message"> // this is meant to increase everytime you click the vote_up just like stackoverflow <span class="vote_count">27</span> <a href="#" class="vote_up"><img src="img/uparrow.png" /></a> <a href="#" class="vote_down"><img src="img/downarrow.png" /></a> </li> </ul>

this is my jquery code:

$(document).ready(function() { $('#statuses').delegate('.vote_up', 'click', function() { //get the id var the_id = $(this).closest('.message').attr('id').split('_').pop(); //the main ajax request $.ajax({ type: "POST", data: "action=vote_up&id=" + the_id, url: "ajax/votes.php", success: function (msg) { // fade in the new vote_count $(this).siblings("span.vote_count").html(msg).fadeIn(); // get the child <img> and set its src $(this).children("img").attr("src", "img/uparrowActive.png"); } }); }); });

EDIT: also the jquery fade.in and change of image src is not working, am i referencing the right span or class(the ajax request is working now)

Answer1:

First thing to jump-out:

<ul class="statuses">

and

$('#statuses')

... the # symbol in jQuery is the id-selector (same as CSS). Since your <ul> is set to class="statuses" then you'll need to use the class-selector:

$('.statuses')

That alone will break all your jQuery

Answer2:

From the jQuery docs:

The beforeSend, error, dataFilter, success and complete options all take callback functions that are invoked at the appropriate times. The this object for all of them will be the object in the context property passed to $.ajax in the settings; if that was not specified it will be a reference to the Ajax settings themselves.

So, try adding context: this to your ajax request options.

Answer3:

Change this

var the_id = $(this).closest('.message').attr('id').split('_').pop();

to this

var the_id = $(this).parents('.message').attr('id').replace('set_', '');

or alternatively

var the_id = $(this).parent().attr('id').replace('set_', '');

if you know that your link's parent element will always be ul.message.

Recommend

  • Matching genre ids with genre names in TMDb with JavaScript (Ember.js)
  • can I change the color of python ttk combobox under windows?
  • how to swap Image in jquery
  • How do I get placemark icons to load over ssl?
  • How to stop onclick from firing before ondblclick in JS/HTML
  • If string is … then replace it with an image?
  • In java, how do you retrieve images from a jar file?
  • window.onbeforeunload in javascript
  • What's wrong with my datatrigger binding?
  • MVVM: Image Bind Source from FileOpenPicker
  • Are there any issues with placing image as background on an extended JFrame?
  • Python PIL to extract number from image
  • What is the use of a session store?
  • Outputting SharePoint Hyperlink Column as URL
  • Why does it draw lines in the wrong place?
  • Floated image with variable width and heading with background image
  • Uncaught TypeError: $(…).select2 is not a function
  • Disable Kendo Autocomplete
  • Simulate click Geckofx vb,net
  • How to view images from protected folder with php?
  • Button click event not firing in jQuery
  • how to save the state in userdefaults of accessory checkmark-iphone
  • MonoTouch: How to download pdf incrementally as indicated in the Apple slides “Building Newsstand Ap
  • How do I get HTML corresponding to current DOM tree?
  • How to have background script and something similar to a default popup?
  • chrome.tabs.executeScript only fires when the Developer Console is open
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • JQuery Internet Explorer and ajaxstop
  • JSON response opens as a file, but I can't access it with JavaScript
  • Python urlparse: small issue
  • Jquery UI tool tip close icon
  • HTML download movie download link
  • Change an a tag attribute in JavaScript based on screen width
  • Getting 'uninitialized constant' error when using delegate in belongs_to in model
  • GridView Sorting works once only
  • Suggestions to manage Login/Logout transitions
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?