EspañolDeutschFrançaisItalianoPortuguêsРусскийΕλληνικά日本語中文(简体)हिन्दी; हिंदीالعربية
Configura come lingua predefinita
Domande di PF - Cose da fare

Come a sostituire interamente di tag all'interno di un tag ?

Come posso sostituire?, all'interno di un'etichetta <etichetta>, il spazi tag esistenti <Dri>?. Per esempio, Ho il seguente:

<label>Aquí va algún texto</label>

e voglio cambiarlo da:

<label>Aquí<br/>va<br/>algún<br/>texto</label>

Che cosa ho cercando con:

$('label').html().replace(' ', '<br/>');

ma non mi funziona.

Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
FishGG fa frequenti 7 anni
2 Risposte
Miglior risposta

È possibile utilizzare il metodo html() con una funzione di callback. Gli spazi vuoti, è possibile utilizzare un'espressione regolare nel metodo replace().

$('label').html(function(i, oldHTML) {
   return oldHTML.replace(/\s+/g, '<br/>');
}

 

Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
Borja ha detto rende 7 anni

Prova di questa forma:

$('label').html($('label').html().replace(' ', '<br/>'));
Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
JuanR ha detto rende 7 anni