javascript - How to get div's ID with unique number in jquery?


I am using a jquery slider in my application.The input type hidden has got some image url paths. I want to get "

   img-paths- <?php echo $omsg_id; ?>

" $omsg_id value into var image_path_id = "#img-paths-"+$(this).data('id');

when i console printed in fire bug, the output was #img-paths-undefined

how to resolve it ?

  <div >
        <?php $imagePathArray = explode(',',$uploads); ?>
<input id="img-paths-<?php echo $omsg_id; ?>" type="hidden" value="<?php echo htmlentities(json_encode($imagePathArray)); ?>" />
    <div id="gallery7-<?php echo $omsg_id; ?>" ></div>
   $(function(e) {

      var image_path_id = "#img-paths-"+$(this).data('id');
      var show_gallery_id = "#gallery7-"+$(this).data('id');

        align: true,
        getViewAllText: function(imgsCount) { return 'View all' }



         <!--<img src="<?php //echo $contentimage; ?>" alt="image post">-->
         <p><?php echo $message; ?></p>



this refers towindow object, thus$(this).data('id') will not return the desired data.

You can directly use$omsg_id in script.

var image_path_id = "#img-paths-<?php echo $omsg_id; ?>";
var show_gallery_id = "#gallery7-<?php echo $omsg_id; ?>";

People are also looking for solutions to the problem: php - I want to overwrite cookie value according to the id


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.