javascript - jquery open div with dynamic id -


i want use jquery open , close div. because code use dynamic , repeated below each other, need use dynamic id.

html:

<div class="categoryratings-review-<?php echo $this->htmlescape($_review->getid())?>" style="display: none;">    <p>text</p> </div>  <span class="showcategoryratings" id="review-<?php echo $this->htmlescape($_review->getid())?>">    <span class="showcategoryratings-text">per category</span> </span> 

i try use jquery, guess php line not working:

$(document).ready(function() {     $('#review-<?php echo $this->htmlescape($_review->getid())?>').click(function() {             $('.categoryratings-review-<?php echo $this->htmlescape($_review->getid())?>').slidetoggle("fast");             $(this).toggleclass('active');     }); }); 

how need edit correctly?

you can without php in javascript.

$(document).ready(function() {     $('.showcategoryratings').click(function() {         var categoryid = $(this).attr('id').split('-')[1];          $('.categoryratings-review-'+categoryid).slidetoggle("fast");         $(this).toggleclass('active');     }); }); 

i think works.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -