Tuesday, July 24, 2012

javascript – HTML replaceWith function with PHP



I am trying to execute this code in javascript:



$(\'#content\').replaceWith(\"<div>\" + <?php echo $tableau_Text?> + \"</div>\");


But is not working for me. It shows nothing to me. When I change the PHP code for something static like:



$(\'#content\').replaceWith(\"<div>Hello World</div>\");


it works perfectly with that.


My html #content definition is:–



<div id=\"content\">
<?php echo $show_menu;?>
</div>


Any idea? Thank you very much!


UPDATE:


The var $tableau_text looks like this:



$tableau_Text = \"<ul class=\'object_list\' id=\'object_list\' data-role=\'listview\' data-inset=\'true\' data-theme=\'c\'>$TableauText</ul>\";


Where $TableauText are the list items in the same format.



$TableauText = <li class=\'menuA\' id=\'menuA\' data-role=\'list-divider\' data-icon=\'false\'>River Flow</li>
<li class=\'menuB\' id=\'menuB\' data-icon=\'arrow-r\'><a href=\'#\' target=\'foo\'>Rossiniere</a></li>
<li class=\'menuB\' id=\'menuB\' data-icon=\'arrow-r\'><a href=\'#\' target=\'foo\'>Montsalvens</a></li>
<li class=\'menuA\' id=\'menuA\' data-role=\'list-divider\' data-icon=\'false\'>Lake Level</li>
<li class=\'menuB\' id=\'menuB\' data-icon=\'arrow-r\'><a href=\'#\' target=\'foo\'>Rossiniere</a></li>
<li class=\'menuB\' id=\'menuB\' data-icon=\'arrow-r\'><a href=\'#\' target=\'foo\'>Montsalvens</a></li>
<li class=\'menuB\' id=\'menuB\' data-icon=\'arrow-r\'><a href=\'#\' target=\'foo\'>Lessoc</a></li>
<li class=\'menuB\' id=\'menuB\' data-icon=\'arrow-r\'><a href=\'#\' target=\'foo\'>Rossens</a></li>
<li class=\'menuB\' id=\'menuB\' data-icon=\'arrow-r\'><a href=\'#\' target=\'foo\'>Maigrauge</a></li>
<li class=\'menuB\' id=\'menuB\' data-icon=\'arrow-r\'><a href=\'#\' target=\'foo\'>Schiffenen</a></li>
<li class=\'menuB\' id=\'menuB\' data-icon=\'arrow-r\'><a href=\'#\' target=\'foo\'>Maigrauge</a></li>


Solution: I had several list elements with the same id which I didn\’t realized after I paste it here and that was making my code crazy…






Rating: 2 out of 5 based on 4 ratings



The post javascript – HTML replaceWith function with PHP appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-html-replacewith-function-with-php.html

No comments:

Post a Comment