EspañolDeutschFrançaisItalianoPortuguêsРусскийΕλληνικά日本語中文(简体)हिन्दी; हिंदीالعربية
डिफ़ॉल्ट भाषा के रूप में सेट करें
PF प्रश्न - फोरम

कैसे मैं एक टैग के भीतर टैग द्वारा रिक्त स्थान की जगह है ?

¿Cómo puedo reemplazar, dentro de una etiqueta <label>, को espacios existentes por etiquetas <br />?. उदाहरण के लिए, tengo lo siguiente:

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

y quiero cambiarlo por:

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

Lo he intentando con:

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

pero no me funciona.

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 पूछा करता है 7 साल
2 जवाब
उत्तम उत्तर

Puedes usar el metodo html() con una función de callback. Para los espacios en blanco puedes usar una expresión regular en el método 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 कहा करता है 7 साल

Prueba de esta 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 कहा करता है 7 साल