Reemplazar el texto pero mantener el elemento hermano con jQuery

17/Abr/2013 248

Problema: WordPress imprime un código HTML con el siguiente formato y necesito modificar sólo el texto, manteniendo el checkbox:

<p class="login-remember">
<input name="rememberme" type="checkbox" id="rememberme"> <!-- mantener -->
Recuérdame <!-- este texto debe ser otro -->
  1. Primera solución: modificar el core del CMS, lo que no me interesa.
  2. Segunda solución: modificar el texto con jQuery, manteniendo el checkbox.

Test 1: lo obvio, reemplazar el texto con text()

$('.login-remember label').text('Recordámelo');

Ver ejemplo 1

En este caso, apesar de sólo querer reemplazar el texto también reemplaza el checkbox.

Test 2: clonar el checkbox, reemplazar el texto con html() y volver a agregar el checkbox clonado

var elemento = $('.login-remember label')
var checkbox = elemento.find('input').clone();
elemento.html(' Recordámelo').prepend(checkbox);

Ver ejemplo 2

Efectivo, no importa dónde o cómo está el texto. Limpiamos todo y volvemos a construir lo que está dentro del label.

Test 3: buscar dentro del contenido del label donde está el texto y reemplazarlo

$('label').contents().last()[0].textContent=' Recordámelo';

Ver ejemplo 3

Dependemos un poco del orden de los elementos dentro del label, pero es una sencilla solución.

¿Cuál es la mejor?

Lo dejo a criterio de cada uno, seguro hay una más rápida que otra. Finalmente no utilicé ninguna de las soluciones anteriores; edité el languages.po y volví a traducir el texto por el que quería. Pero el desafío fue interesante, y el aprendizaje quedó.


  1. [#]

    you are in reality a just right webmaster. The web site loading speed is incredible.
    It sort of feels that you’re doing any unique trick.

    Also, The contents are masterpiece. you have performed a magnificent process
    on this matter!

  2. FelipeHaw [#]

    buying from viagra canada
    the canada pharmacy alternatives to viagra cheap viagra without prescription canadian pharmaceuticals viagra forum viagra and women cialis of canada side effects viagra canadian pharmacy no prescription canadian generic viagra
    ed drugs – canada canadian pharmacies without prescriptions canada pharmacy online viagra canada with prescription generic viagra from canada

  3. HenryUnfiP [#]

    gay the dating game porn
    free gay dating sim
    best dating sites for gay men

  4. gay zoophilia dating [#]

    manhunt dating gay

  5. disco gay dating site login [#]

    gay relationship dating books

  6. [#]

    ivermectinДѓ cumpДѓrДѓ online Reemplazar el texto pero mantener el elemento hermano con jQuery | CSSLab | Laboratorio de ideas web ivermectin tablets

  7. PeterCed [#]

    best price viagra
    prescription viagra online canada canadian-meds free viagra viagra stories canadian pharmacy for viagra viamedic .com canadian tadalafil order cialis in canada canada meds
    international drug mart buy cialis online in canada order cheap viagra discount rx drugs viagra overnight shipping

  8. ivermectin dosage [#]

    oral ivermectin cost Reemplazar el texto pero mantener el elemento hermano con jQuery | CSSLab | Laboratorio de ideas web stromectol

  9. MarvinFuh [#]

    buying viagra in canada
    viagra 100 canadian levitra online generic viagra canadian drug generic viagra from india cialis – canada order cialis from canada viagra pharmacy viagra side effects
    brand name viagra drug store viagra free sample best canadian pharcharmy online is generic viagra safe

  10. [#]

    I love reading through a post that can make men and women think.
    Also, many thanks for allowing me to comment! asmr asmr

  11. HenryUnfiP [#]

    gay college dating
    gay india dating site
    gay fresno dating

  12. FelipeHaw [#]

    viagra overnight
    internet pharmacy drug online canada rx pharmacy canada.viagra [url=]viagra overdose[/url] cialis daily canada list of canada online pharmacies best canadian pharmacies shipping to usa canadian viagra online pharmacy [url=]canadian pharmacy with viagra[/url]
    online drugstore cialis over the counter in canada discount cialis buy viagra online [url=]canada online drugs[/url]

  13. stromectol [#]

    ivermectin 3mg Reemplazar el texto pero mantener el elemento hermano con jQuery | CSSLab | Laboratorio de ideas web stromectol 3mg

  14. gay dating service [#]

    american gay dating sites

  15. what quest bars [#]

    Generally I do not read post on blogs, but I would like to
    say that this write-up very forced me to try and do so!
    Your writing taste has been surprised me. Thanks, very great post.

    quest bars quest bars

  16. nerd dating gay [#]

    best dating sites for gay

  17. [#]

    Wow, awesome weblog layout! How lengthy have you been blogging for?
    you make running a blog glance easy. The total glance of your website
    is magnificent, as well as the content!
    scoliosis surgery scoliosis surgery

  18. MarvinFuh [#]

    buying cialis canada
    viagra no prescription viagra sample my canadian pharmacies order cialis viagra ingredients low price cialis viagra online without prescription buying viagra online cialis discount
    buy cialis from us pharmacy http://www.canadian pharmacy cheap generic viagra online drug prices

  19. [#]

    Asking questions are really good thing if you are not understanding anything completely, however this paragraph presents pleasant
    understanding yet. cheap flights cheap flights

  20. MarvinFuh [#]

    canadian pills online
    viagra india pharmacy viagra erections buy cialis canada free viagra sample pack pharmacy rx one 60 mg cialis online pharmacy without prescription order cialis online canada by pills from canada cost of viagra in canada buy viagra no prescription
    herbal viagra reviews sildenafil generic viagra pro lowest cost cialis

  21. gay geek dating [#]

    gay fat dating

  22. it quest bars [#]

    What’s Taking place i’m new to this, I stumbled upon this I’ve found It absolutely useful and it has helped me out loads.

    I am hoping to give a contribution & help different
    users like its aided me. Great job. quest bars quest bars

  23. teen gay dating [#]

    gay dating sites in america

  24. MarvinFuh [#]

    buy viagra without a prescription
    universal pharmacy cost of cialis at walgreens online rx prescription drugs from canada prices walmart drug prices without insurance cheap viagra from canada price of cialis canada purchase cialis from canada cialis canadian
    buy discount viagra viagra brand sale canadian pharmacy and viagra canadian online pharmacy for viagra viagra online canada pharmacy

  25. [#]

    Hi, I wish for to subscribe for this weblog to get newest updates, so where can i do it please assist.

    ps4 ps4 games

  26. [#]

    Do you have a spam problem on this website; I also am a blogger, and I was
    curious about your situation; we have developed some nice
    practices and we are looking to trade methods with
    others, please shoot me an email if interested. scoliosis
    surgery scoliosis surgery

  27. [#]

    Greetings! Very useful advice within this post!
    It is the little changes that make the greatest changes.
    Thanks a lot for sharing! scoliosis surgery scoliosis surgery

  28. [#]

    whoah this blog is fantastic i really like reading your posts.
    Keep up the great work! You realize, lots of people are searching round for this info,
    you can help them greatly. cheap flights cheap

  29. HenryUnfiP [#]

    gay virgin dating
    jack d gay dating
    why is gay dating so difficult

  30. [#]

    Thanks for sharing your thoughts on that. Regards quest bars quest bars

  31. HenryUnfiP [#]

    free gay male dating
    free gay dating sim english
    gay male dating sites us

  32. HenryUnfiP [#]

    dwarves gay dating
    gay dating websites new zealand
    gay dating dc

  33. cetirizine 10mg tablets [#]

    cetirizine 10mg cost –

  34. stromectol for sale [#]

    General Information Fro this product buy ivermectin online india can humans take ivermectin paste reddit canadian pharmacy ivermectin 12 mg stromectol

  35. [#]

    ivermectin 6mg ivermectin tablets dosage stromectol tabletter

  36. allegra [#]

    zyrtec 90 count price –

  37. zyrtec hives relief [#]

    fexofenadine hcl –

  38. pharmacepticacom [#]

    can i buy sildenafil over the counter

  39. stromectol [#]

    ivermectina en humanos invermechtin prescription drug stromectol

  40. prednisol [#]

    prednisone indications

  41. how to obtain ivermectin [#]

    ivermectin गोली लागत ivermectin tablets order stromectol 3 mg dosage

  42. bactrim [#] Trimethoprim bnf

  43. bbblicuuq [#]

    yTEYO7 ahywgdmmsplk, [url=]kbvrqnrjgsah[/url], [link=]kyermatkxhse[/link],

  44. modafinil [#] modafinil side effects

  45. bactrim dosage [#]

    co trimoxazole dosage for adults bactrim side effects

  46. ivermectin 6 mg [#]

    Accustomed Dope Fro this outcome ivermectin 12 mg ivermectin for humans ivermectin 6 mg ivermectin tablets stromectol

  47. GustavoVet [#]

    readwritethink essay map
    buy college essays