Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-07-2009, 05:56 PM   PM User | #1
carlitos_way
New Coder

 
Join Date: Mar 2007
Location: italy
Posts: 94
Thanks: 1
Thanked 1 Time in 1 Post
carlitos_way is an unknown quantity at this point
Lightbulb [JQUERY] how do I parse text?

Hi All,

I just started using jquery and drupal together. It happens I have an article that is contained inside a textarea, in which I can have various html tags.
As an example see the code below:
Quote:
<img src="http://localhost/drupal/sites/default/files/media_1952.jpeg" />Questo vuol essere un veloce pro-memoria per professionisti e manager IT in cerca di spunti per arricchire le proprie competenze e migliorare la gestione dell'IT aziendale. Si tratta di una rapida rassegna di nove siti web che si sono distinti negli ultimi mesi per originalità e successo. Anche se sono americani, consultarli può essere molto utile anche dall'Italia, per raccogliere idee su come innovare senza dover spendere un sacco di denaro.<br/><table border="0"><tr><td valign=top>1) LinkedIn. Quotidiani e TV, anche in Italia, stanno dedicando moltissimo spazio a Facebook, considerato (spesso con articoli e servizi piuttosto superficiali) un enorme fenomeno di costume. Ma il sito che si sta dimostrando un vero e proprio 'standard de facto' per il social networking professionale è LinkedIn. Nel 2008 ha raddoppiato gli iscritti (oggi sono oltre 30 milioni nel mondo) e ha raccolto oltre 75 milioni di dollari di venture capital, dettaglio non da poco in un periodo come questo.

Le nuove funzionalità introdotte negli ultimi mesi hanno permesso a LinkedIn di aggiudicarsi diversi premi e award come sito di relazioni professionali più utile. Anche noi recentemente abbiamo parlato di come gestire in modo ottimale le proprie relazioni su LinkedIn. Negli USA, ma anche in molti Paesi del Nord Europa, tenere sempre aggiornato il proprio profilo LinkedIn è ormai considerato il metodo migliore per 'mettere in mostra' in azienda e all'esterno la propria immagine professionale, e anche per cercare lavoro. In America spesso non si manda più il curriculum, ma il link al proprio profilo LinkedIn, e anche chi cerca personale dà sempre più spesso un'occhiata a questo sito.
</td><td valign=top>2) Google Apps for Business. Chiamiamolo come vogliamo, cloud computing o software-as-a-service, ma questo è il futuro e a volte già il presente per diverse aree d'attività dei dipartimenti IT aziendali. Gli IS Manager nel 2009 saranno più che mai sotto pressione per ridurre i costi, e secondo molti consulenti uno dei modi migliori per farlo è avviare un progetto pilota Google Apps in qualche area, per esempio l'e-mail aziendale, la condivisione di documenti o di video. Anche in Italia ci sono già casi concreti: ne abbiamo parlato in questo articolo.
</td><td valign=top>
Pagina successiva


L'articolo continua:

* I due grandi fenomeni
* Virtualizzazione, sicurezza e 'green IT'
* Gestire la comunicazione e sviluppare 'open'

</td></tr></table>
inside of this article there is an img and a table.

Now I need to read all the tag elements of the textarea, for example read all the tags img (and their attributes), or read all the tags td(and their attributes too).

this way I will have an array containing all the imgs, all the tds, etc..

At the moment, I access to the text contained in the textarea by using this code:

Code:
var textareaContent = $('#edit-body').text();
but if I try to do something like
Code:
var tmp = $('#edit-body').find('img');
it doesn't work, it gives me 0 in a consequent tmp.length.

So, do you know how can I parse the above text to get what I need with jquery?

Thankss for any help
Best regards
cb
carlitos_way is offline   Reply With Quote
Old 01-07-2009, 07:16 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
i dont use jquery, but you can probably use it to simplify the dom code.

Code:
var tel = document.createElement("div");
tel.innerHTML = $('#edit-body').text();
now we have an object where we can use dom methods.


//simple example: get an array of the .src of all images:
Code:
var r=[], tags=tel.getElementsByTagName("img"), mx=tags.length, i=0;
for(i;i<mx;i++){
   r[i]= tags[i].src;
}

alert(r.join("\n"));
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Old 01-08-2009, 10:47 AM   PM User | #3
carlitos_way
New Coder

 
Join Date: Mar 2007
Location: italy
Posts: 94
Thanks: 1
Thanked 1 Time in 1 Post
carlitos_way is an unknown quantity at this point
Hi rnd_me,

you found the problem, I wasn't able to find the way to use all the DOM capabilities because I was working on a string, and not on an object.

Thanks very much for your suggestion!
carlitos_way is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:31 AM.


Advertisement
Log in to turn off these ads.