By putting php code inside my jquery script

I am using jQuery isotope. I found out how to reLayout after click when it displays the textbox for a comment.

But my problem is jQuery, when you click on the comment button, it opens all the comment fields on the page instead of a single comment.

I was wondering if it would be possible to put my COMMENT_ID in a script so that it only opens one block and not all of them.

my code: (it doesn't work)

$('.commentopen').click(function() {
  $('.comment '<php echo $LOGGER_ROW['COMMENT_ID'] ?>').slideDown(1000, function() {
    $('#container').isotope('reLayout');
  });
});

      

Any help is appreciated.

+3


source to share


3 answers


When rendering your HTML, if you give each comment an href attribute, you can use the jquery function attr()

to grab that link and only expand that comment.

For example:

$('.comment').click(function() {
    var id = $(this).attr('href');
    $('.comment#' + id).slideDown(1000, function() {
         $('#container').isotope('reLayout');
    });
});

      

I modified my code a bit so that all comments are treated as elements of the .comment class.



Each comment also has a unique identifier with it, and therefore one of all available comments opens correctly.

Here is a working solution: http://jsfiddle.net/HDBwY/

Hope it helps.

+1


source


Your syntax is bad. Consider this snippet:

$('.comment '<php echo $LOGGER_ROW['COMMENT_ID'] ?>').slideDown

      

When you substitute PHP, it becomes:



$('.comment 'x').slideDown

      

There is a separate quote. Perhaps it should be a pound instead?

$('.comment #<php echo $LOGGER_ROW['COMMENT_ID'] ?>').slideDown

      

0


source


$('.commentopen').click(function() {
    var id = $(this).attr('id');
    $('.comment' + id).slideDown(180, function() {
         $('#container').isotope('reLayout');
    });
});

      

heres what i ended up doing (which still didn't work) i gave each textarea (.comment) an id and then i gave a comment link to open a textarea (.commentopen) with exactly the same id and then using this function , I got the same id as for comments. and in html they seem to match line for line. but it still doesn't work.

-1


source







All Articles