Solved

Jquery does not recognize the spaces inbetween paragraphs in .txt document

Posted on 2008-06-19
7
393 Views
Last Modified: 2010-05-18
does anyone know any code that works with j query that will read the spaces inbetween pargraphs of a text document.  

I've attached the code im using to define the query and how it is executed.  

can you show me any code i can add to this so that j query will see that the txt document has paragraphs and makes the proper spacing for each paragraph.


Thank you

######## this is what is in my header  ##############
 

<script type="text/javascript" src="http://www.djmichaelray.com/dreamchasers/articles/top_three_articles/jquery-1.2.6.js"></script>

<script type="text/javascript">

$(document).ready(function() {

        $.get("/dreamchasers/headline2.txt", function(data){

                $('.headlinetwo').text(data);

        });

});

$(document).ready(function() {

        $.get("full_article_two.txt", function(data){

                $('.articletwo').text(data);

        });

});

</script>
 

########## This is an example of how i would call up the script######
 

     <div id="below">

    	  <div class="articletwo"> <--- this calls up the script

          </div>

          <br />

       <a href="/dreamchasers/top_three_articles/article_two.html"  class="links">Next Article</a>

    

     </div>

Open in new window

0
Comment
Question by:djmichaelray
7 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 21831760
Not my field!
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 21836475
You will need to search for newline characters and replace them with <p> tags. Also, on what you posted you are missing an element/tag with class="headlinetwo". Try:
<script type="text/javascript" src="http://www.djmichaelray.com/dreamchasers/articles/top_three_articles/jquery-1.2.6.js"></script>

<script type="text/javascript">

$(document).ready(function() {

        $.get("/dreamchasers/headline2.txt", function(data){

                $('.headlinetwo').html("<p>" + data.replace(/[\n\r]/g, "</p><p>") + </p>);

        });

});

$(document).ready(function() {

        $.get("full_article_two.txt", function(data){

                $('.articletwo').text( "<p>" + data.replace(/[\n\r]/g, "</p><p>") + </p>);

        });

});

</script>

 

########## This is an example of how i would call up the script######

 

     <div id="below"><div class="headlinetwo"></div>

    	  <div class="articletwo"></div>

          <br />

       <a href="/dreamchasers/top_three_articles/article_two.html"  class="links">Next Article</a>

    

     </div>

Open in new window

0
 

Author Closing Comment

by:djmichaelray
ID: 31469027
Don't use this as an actual solution for anyhting mac related
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 82

Expert Comment

by:hielo
ID: 21839054
The fact that jQuery and Mac's do not agree should have no weight on the grade. What I gave you works correctly on the browsers in which I tested it. Technically speaking what I posted is correct. That grade in unfair.
0
 

Author Comment

by:djmichaelray
ID: 21839082
Im sorry you feel that way.   I do want to give you your proper recognition for what you have done.   However I had to post this question over 7 times and each time I was very specific that it had to be cross platform compatible.  As a client relying on the experts advice NObody informed me that it would not work on anything browser related to mac even though i posed questions relating to safari and mac oppertaion.  So instead of me taking another approach early in the game, I've wasted 2 weeks of programming on a system that doesn't even function well that well.

I did appreciate you trying to fix it as much as you could and I thought i was being more than fair by awarding all the points to you in every single question even though it didn't answer my question at all.  Im sorry about the B if i could change it I would but oyu have to understand where my level of frustration has come in on this.   I will forward an email to Expert-exchange requesting that the grades be changed to A's beacuse i believe in your ability and if your solution works in some windows system than im sure it is true, but I hope you empathize with my situation in regards to being given information from an expert that works on certain systems and not others.  If you can't provide a solution that works at the bare minimum with the most update version of the top browsers on the leading operating systems windows and mac, than its really not a solution in todays market.    Or at the bare minimun the solution should be presented in a manor that explains what platforms your code works on,  links where we can research the methods emplyed so that we don't have to keep comming back to the code.  

In The end Hielo I think your an excellent Expert and I would love for you to answer my questions in the future as you have always tried your best to get me the correct information.  If you know of a better approach in which i can have your grade changed please dont hesitate to inform me how.

Respectfully
Michael
0
 
LVL 42

Expert Comment

by:David S.
ID: 21842080
Differing operating systems use different characters to signify new-lines.

In what way did hielo's code not work?
0
 
LVL 82

Expert Comment

by:hielo
ID: 21846509
>>Differing operating systems use different characters to signify new-lines
Correct. What I know for a fact about Macs is that they use \r instead of \n for newline characters. That's why I used [\n\r] in the RegEx - to account for Windows and Mac systems.

>>In what way did hielo's code not work?
Exactly! The proper course of action would be to describe what problems you are having. I looked at the jQuery source code and it does address safari issues, so I would expect the core library to work. So, what's not working for you? Was there a recent update to the browser perhaps? Are you using the most recent version of jQuery?

>>However I had to post this question over 7 times and each time I was very specific that it had to be cross platform compatible
if you look at your original  post here, there is no indication of cross platform issues. You are asking for a jQuery-specific solution, which is what you got.

>>As a client relying on the experts advice NObody informed me that it would not work on anything browser related to mac even though i posed questions relating to safari and mac oppertaion.
Probably because not everybody has Macs. Most of us are volunteers - we volunteer our time to help YOU. We are EE employees, so we are not in a EE office equiped with Macs and/or PCs where we may test our suggestions. Under these circustances, we the "experts" rely on YOU, the posters! You need to provide useful feedback. I've had "It doesn't work" as feedback. That does not tell me much.

>>So instead of me taking another approach early in the game, I've wasted 2 weeks of programming on a system that doesn't even function well that well.
Believe me, I understand your frustration (been there, done that - multiple times)!

On another note, I just looked at the source code of:
http://www.djmichaelray.com/dreamchasers/articles/top_three_articles/article_two.html

and that is NOT doing the necessary replacing that I had suggested. Most likely you did not copy something correctly along the way, and when you tested it, it did not work for you for this same reason. Save the code below as Hielo.html:
http://www.djmichaelray.com/dreamchasers/articles/top_three_articles/Hielo.html

and try it. But this time, please, save it as Hielo.html. Last time I asked you to do this, you updated your original and somewhere in between multiple suggestions you must have confused your files and failed to update the right file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head><base href="http://www.djmichaelray.com/dreamchasers/articles/top_three_articles/article_two.html"/>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>Dream Chasers</title>

<meta name="keywords" content="" />

<meta name="description" content="" />

<link href="/dreamchasers/default.css" rel="stylesheet" type="text/css" media="screen" />

<script type="text/javascript" src="http://www.djmichaelray.com/dreamchasers/articles/top_three_articles/jquery-1.2.6.js"></script>

<script type="text/javascript">

$(document).ready(function() {

        $.get("full_article_one.txt", function(data){

	   	data=("<p>"+data.replace(/\.[ ][ ]/g,".&#160;&#160;").replace(/[\r\n\f]/g,"</p><p>") + "</p>")

                $('.articleone').html(data);

        });

});

$(document).ready(function() {

        $.get("/dreamchasers/headline1.txt", function(data){

	   	data=("<p>"+data.replace(/\.[ ][ ]/g,".&#160;&#160;").replace(/[\r\n\f]/g,"</p><p>") + "</p>")

                $('.headlineone').html(data);

        });

});

$(document).ready(function() {

        $.get("/dreamchasers/headline2.txt", function(data){

	   	data=("<p>"+data.replace(/\.[ ][ ]/g,".&#160;&#160;").replace(/[\r\n\f]/g,"</p><p>") + "</p>")

                $('.headlinetwo').html(data);

        });

});

$(document).ready(function() {

        $.get("full_article_two.txt", function(data){

	   	data=("<p>"+data.replace(/\.[ ][ ]/g,".&#160;&#160;").replace(/[\r\n\f]/g,"</p><p>") + "</p>")

                $('.articletwo').html(data);

        });

});

</script>

</head>

<body>

<div id="wrapper">

<div id="header">

        <div id="logo">

                <img src="/dreamchasers/images/dbanner.jpg" alt="" width="890" height="160"/>

        </div>

    <br />

</div>

<div id="menu">

        <ul>

                <li><a href="/dreamchasers/la.html">Home</a></li>

                <li class="current_page_item"><a href="/dreamchasers/top_stories.html">Top Stories </a>

        <li><a href="/dreamchasers/scene.html">Clubs</a></li>

                <li><a href="/dreamchasers/photos.html">Photos</a></li>

                <li><a href="/dreamchasers/videos.html">Videos</a></li>

        <li><a href="/dreamchasers/aboutus.html">About</a></li>

                <li><a href="/dreamchasers/contact.html">Contact</a></li>

        </ul>

</div>

 

<div id="page">

        <div id="ads"><a href="#"><img src="/dreamchasers/images/ad160x600.gif" alt="" width="160" height="600" /></a></div>

        <div id="content">

                <div class="post">

                        <div class="title">

               </div>

 

<div class="headlinetwo"></div>

<div class="articletwo"></div>

 

                         <h2 ><a href="/dreamchasers/articles/top_three_articles/article_one.html" class="headlineone"></a> </h2>

                                <p><small>by <a href="#">Darron Anderson</a></small></p>

                        </div>

            <div class="entry">

              <p><a href="/dreamchasers/articles/top_three/article_one.html"><img src="/dreamchasers/images/artpic1_large.jpg" alt="" width="410" height="400" class="left"/></a></p>

              <p>&nbsp;</p>

              <p>&nbsp;</p>

              <p>&nbsp;</p>

              <p>&nbsp;</p>

              <p>&nbsp;</p>

              <p>&nbsp;</p>

              <p>&nbsp;</p>

              <p>&nbsp;</p>

              <p>

                <br />

                

                   </p>

 

         <br />

         <br />

     <div id="below">

          <div class="articleone"></div>

         <br />

         <a href="/dreamchasers/top_three_articles/article_two.html" class="links">Next Article</a>

    </div>      

 

         

      </div> 

                <br />

        </div>

  

        <div id="sidebar">

                <ul>

                        <li id="categories">

                                <h2>Nightlife Planner</h2>

                                <ul>

                                        <li><a href="/dreamchasersweek_planner/monday.html">Monday</a></li>

                                        <li><a href="/dreamchasersweek_planner/tuesday.html">Tuesday</a></li>

                    <li><a href="/dreamchasersweek_planner/wednesday.html">Wednesday </a></li>

                    <li><a href="/dreamchasersweek_planner/thursday.html">Thursday </a></li>

                    <li><a href="/dreamchasersweek_planner/friday.html">Friday </a></li>

                    <li><a href="/dreamchasersweek_planner/saturday.html">Saturday </a></li>

                    <li><a href="/dreamchasersweek_planner/sunday.html">Sunday </a></li>

                                

                    

                                </ul>

                        

                      <h2>On The List</h2>

                      <ul>

                        <li><a href="/dreamchaserscategories/style_guide.html">Style Guide</a></li>

                        <li><a href="/dreamchaserscategories/music.html">Music</a></li>

                        <li><a href="/dreamchaserscategories/club_etiquette.html">Club Etiquette</a></li>

                        <li><a href="/dreamchaserscategories/hotspot_watch.html">HotSpot Watch</a></li>

                        <li><a href="/dreamchaserscategories/on_the_rise.html">On The Rise</a></li>

                      </ul>

                    </li>

            

                </ul>

        </div>

</div>

<div id="footer">

        <p class="legal">

                &copy;2007 Dream Chasers. All Rights Reserved.

        </p>

        

 </div>

</div>

<!-- end footer -->

</body>

</html>

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

13 Experts available now in Live!

Get 1:1 Help Now