picwizz Posted March 15, 2013 Share Posted March 15, 2013 hi, im having trouble with the following code this is just one line from the code which is not working $('.likehide'+pid).html('<a href="#" onclick="unlike(pid); return false;">unlike</a>'); The code works but when i inspect the element, it shows up like this <a href="#" onclick="unlike(pid); return false;">unlike</a> it should not have "pid" it should be displaying the pid value What am i doing wrong in the jquery code? Thanks Link to comment https://forums.phpfreaks.com/topic/275702-there-is-an-error-with-this-onclick-functon/ Share on other sites More sharing options...
requinix Posted March 15, 2013 Share Posted March 15, 2013 You put literally "pid" in the string. If you want a variable then concatenate it in just like you did for the '.likehide'+pid. Link to comment https://forums.phpfreaks.com/topic/275702-there-is-an-error-with-this-onclick-functon/#findComment-1418841 Share on other sites More sharing options...
picwizz Posted March 15, 2013 Author Share Posted March 15, 2013 i have done that here is the full function function like(pid){ $.post('inc/like.php', {pid:pid}, function(data){ if(data == "yes"){ countlike(pid); $('.likehide'+pid).html('<a href="#" onclick="unlike(pid); return false;">unlike</a>'); } else { alert("error:"+ data); } }); } Link to comment https://forums.phpfreaks.com/topic/275702-there-is-an-error-with-this-onclick-functon/#findComment-1418852 Share on other sites More sharing options...
requinix Posted March 15, 2013 Share Posted March 15, 2013 $('.likehide'+pid).html('unlike');No you haven't. It still has "pid" directly in the string. [edit] See that green? That means it's a string. "pid" is in the green so that means it's a string too. Link to comment https://forums.phpfreaks.com/topic/275702-there-is-an-error-with-this-onclick-functon/#findComment-1418854 Share on other sites More sharing options...
nogray Posted March 15, 2013 Share Posted March 15, 2013 try this $('.likehide'+pid).html('<a href="#" onclick="unlike('+pid+'); return false;">unlike</a>'); Link to comment https://forums.phpfreaks.com/topic/275702-there-is-an-error-with-this-onclick-functon/#findComment-1418857 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.