AndyPSV Posted December 10, 2011 Share Posted December 10, 2011 jQuery(function($) { $('.<% $r.id %><% if $r.id_to <> '' %>_<% $r.id_to %><% /if %>_').click(function() { $('.<% $r.id %><% if $r.id_to <> '' %>_<% $r.id_to %><% /if %>').toggle(); }); $('.comment_<% $r.id %><% if $r.id_to <> '' %>_<% $r.id_to %><% /if %>_').click(function() { $('.<% $r.id %><% if $r.id_to <> '' %>_<% $r.id_to %><% /if %>').show(); $('#comment_<% $r.id %><% if $r.id_to <> '' %>_<% $r.id_to %><% /if %>').focus(); }); }); please leave the variables (I've purposely left them, because its the problem) function(id....... Quote Link to comment https://forums.phpfreaks.com/topic/252884-jquery-how-to-modify-code-to-function/ Share on other sites More sharing options...
AndyPSV Posted December 10, 2011 Author Share Posted December 10, 2011 ok, I've did it function toggleCommentBox(id,id_to) { $('.'+id+id_to+'_').click(function() { $('.'+id+id_to+'').toggle(); }); $('.comment_'+id+id_to+'_').click(function() { $('.'+id+id_to+'').show(); $('#comment_'+id+id_to+'').focus(); }); } jQuery(function() { toggleCommentBox('<% $r.id %>','<% if $r.id_to <> '' %>_<% $r.id_to %><% /if %>'); }); my next problem is, when I've got $('.'+id+id_to+'').show(); it needs to stay like this? because for example, if I use $('.'+id+id_to).show(); IT DON'T WORKS Quote Link to comment https://forums.phpfreaks.com/topic/252884-jquery-how-to-modify-code-to-function/#findComment-1296542 Share on other sites More sharing options...
AndyPSV Posted December 10, 2011 Author Share Posted December 10, 2011 + how to deal with such thing: function viewAllComments(id,id_to) { $('#view_all_c'+id+id_to+'_').click(function() { $('#view_all_c'+id+id_to+'').empty().html('<div class="comment" style="padding-left:10px"><img src="<% $TPL %>i/ico/loader.gif" style="margin-top:6px" alt=""/></div>'); $('#view_all_c'+id+id_to+'').load('<% $URL %>/c/[b]<% if $r.id_to == '' %>q<% else %>a<% /if %>/<% $r.id %>[/b]'); $('#view_all_c'+id+id_to+'_Hide').hide(); }); } <% if $r.id_to == '' %>q<% else %>a<% /if %>/<% $r.id %>, id -> <% $r.id %>; id_to -> <% $r.id_to %> Quote Link to comment https://forums.phpfreaks.com/topic/252884-jquery-how-to-modify-code-to-function/#findComment-1296546 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.