Solved

php with embedded javascript outputs newlines on HTML tags?

Posted on 2013-11-30
6
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't get video to center on page 2 45
JSON help 8 46
Save data in two Database, Asp 2 68
Displaying Text in Columns in HTML 3 32
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

734 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