Solved

php with embedded javascript outputs newlines on HTML tags?

Posted on 2013-11-30
6
398 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
grab and show facebook pages event calendars 6 46
angularls and plnkr 14 19
Help cleaning out CSS 2 32
onOpen 14 43
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now