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() {


Any help is appreciated.


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() {


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:

Hope it helps.



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




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


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.



All Articles