Solved

php with embedded javascript outputs newlines on HTML tags?

Posted on 2013-11-30
6
402 Views
Last Modified: 2013-12-01
I have a php page with JavaScript to be used on a wordpress page,but when the page is generated all <div> <p> etc. appends new lines. Example :

Test.php ->

<script type="text/javascript">
alert('hello<div>world</div>');
</script>
When I view-source there is new lines on each html-tags : <div><p> - which breaks the JavaScript syntax

I tried to remove filter wpautop on content, but no go :(

Thanks
php-newlines.PNG
0
Comment
Question by:Eidos_IT
6 Comments
 
LVL 15

Expert Comment

by:eemit
ID: 39687676
You should use Element.html like this:
<div id="my-pageid">
<div id="id-to-insert-html">
</div>

- - -

<script>
var el = document.getElementById('id-to-insert-html');
el.html = '<div><p>hello world</p></div>';
</script>
0
 
LVL 2

Expert Comment

by:goubun
ID: 39687782
I think that the problem is because you are inserting the code in visual editor mode and you have to insert that only in text mode, You can change the mode of the editor in the right-top tab in the entry editor.
0
 

Author Comment

by:Eidos_IT
ID: 39687805
The issue is not the code it self, the alert stuff is just an example and not relevant.

The reason is that I am using a plugin for wordpress that just dont work, so I found out that the javascript is broken due to the line breaks and <p>.

I can't see this as an editor issue, the line break is happening in the middle of a string, and I am using clean nano on linux.

This is clearly a wordpress issue/feature, because if I run the page as a normal php page on apache2 there is no issues.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Accepted Solution

by:
duncanb7 earned 500 total points
ID: 39687969
take a look at this , and just try it on link-1 replace img tag by your tag or *  in preg_replace for similar issue as yours

link-1 http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/

linke-2 take a look if have time
http://sww.co.nz/solution-to-wordpress-adding-br-and-p-tags-around-shortcodes/

Hope it will give your some hint

Duncan
0
 

Author Comment

by:Eidos_IT
ID: 39688752
Duncan this is clearly in the right direction - THX
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 39688766
Thanks for your pt

Hava a nice day

Duncan
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question