Hi, here is what i have. <script> function myFunction() { document.getElementById("id").innerHTML="<?php echo $id ?>"; } </script> <a class="play" onclick="myFunction()"></a> <span id="id"></span> Code (markup): I need to get id, like 678 and not <span id="id">678</div> THX
this will replace the value id with variable id 678, use attr var id= 678; $('span').attr('id', id); Code (markup):
Thx but this didn't work. I have change code to work in wp. <script type="text/javascript"> $(document).ready(function() { $('.play-<?php echo $id ?>').click( function() { $('#id').html("<?php echo $id ?>"); }); }); </script> <a class="play play-<?php echo $id ?>"></a> <span id='id'></span> Code (markup):
jQuery's documentation for selectors with multiple classes says something like this: $('.class1.class2') selects and element that has class="class1 class2". Also, jQuery expects .class selector to return an array of objects. So you can easily set that play-678 as an id="678" or if you can't change the id just use the .data('play') function corelating with data-play="678" (only if you already have an unique id for that element). I'm not sure what are you trying to accomplish, but hope it's the solution for you.