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">
<label>
<input name="rememberme" type="checkbox" id="rememberme"> <!-- mantener -->
Recuérdame <!-- este texto debe ser otro -->
</label>
</p>
  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ó.

Comentarios

  1. http://t.co [#]

    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 https://datinggayservices.com/

  5. disco gay dating site login [#]

    gay relationship dating books https://dating-gaym.com/

  6. ivermectin1.com [#]

    ivermectinДѓ cumpДѓrДѓ online Reemplazar el texto pero mantener el elemento hermano con jQuery | CSSLab | Laboratorio de ideas web https://ivermectin1.com/ ivermectin tablets

  7. PeterCed [#]

    best price viagra
    prescription viagra online canada canadianpharmacymeds.com 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 https://ivermectin1.com/ stromectol

  9. MarvinFuh [#]

    buying viagra in canada
    viagra 100 canadian levitra online generic viagra canadian drug generic viagra from india canadameds.com 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. app.gumroad.com [#]

    I love reading through a post that can make men and women think.
    Also, many thanks for allowing me to comment! asmr https://app.gumroad.com/asmr2021/p/best-asmr-online 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=https://pbase.com/topics/clefgarden95/how_to_order_as_well_as_usag]viagra overdose[/url] cialis daily canada list of canada online pharmacies best canadian pharmacies shipping to usa canadian viagra online pharmacy [url=https://fkwiki.win/wiki/Post:How_To_Order_As_Well_As_Usage_Your_Common_Cialis_Online_Without_Prescription]canadian pharmacy with viagra[/url]
    online drugstore cialis over the counter in canada discount cialis buy viagra online [url=http://filmsgood.ru/user/yachtedward61/]canada online drugs[/url]

  13. stromectol [#]

    ivermectin 3mg Reemplazar el texto pero mantener el elemento hermano con jQuery | CSSLab | Laboratorio de ideas web http://ivermectin1.com/ stromectol 3mg

  14. gay dating service [#]

    american gay dating sites https://gayonlinedating.net/

  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 http://j.mp/3C2tkMR quest bars

  16. nerd dating gay [#]

    best dating sites for gay https://gaydatingcanada.com/

  17. bit.ly [#]

    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 https://0401mm.tumblr.com/ 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 viamedic.com buying viagra online cialis discount
    buy cialis from us pharmacy http://www.canadian pharmacy cheap generic viagra online canadianpharmacymeds.com drug prices

  19. http://bitly.com [#]

    Asking questions are really good thing if you are not understanding anything completely, however this paragraph presents pleasant
    understanding yet. cheap flights http://1704milesapart.tumblr.com/ 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 canadiandrugstore.com lowest cost cialis

  21. gay geek dating [#]

    gay fat dating https://gay-singles-dating.com/

  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
    http://bit.ly/3C2tkMR quest bars

  23. teen gay dating [#]

    gay dating sites in america https://gaydatinglosangeles.com/

  24. MarvinFuh [#]

    buy viagra without a prescription
    universal pharmacy cost of cialis at walgreens northwestpharmacy.com 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. j.mp [#]

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

    ps4 https://bitly.com/3nkdKIi ps4 games

  26. http://coub.com/stories/962966-scoliosis-surgery [#]

    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 https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

  27. http://bitly.com [#]

    Greetings! Very useful advice within this post!
    It is the little changes that make the greatest changes.
    Thanks a lot for sharing! scoliosis surgery https://0401mm.tumblr.com/ scoliosis surgery

  28. tinyurl.com [#]

    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 http://1704milesapart.tumblr.com/ cheap
    flights

  29. HenryUnfiP [#]

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

  30. http://www.iherb.com [#]

    Thanks for sharing your thoughts on that. Regards quest bars https://www.iherb.com/search?kw=quest%20bars 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 – https://allergyd.com

  34. stromectol for sale [#]

    General Information Fro this product
    https://stromectolivermect.com buy ivermectin online india
    https://ivermectinstrom.com can humans take ivermectin paste
    https://stromectolivermect.com reddit canadian pharmacy
    https://ivermectinstrom.com ivermectin 12 mg
    https://ivermectinsts.com stromectol

  35. stromectolforte.com [#]

    ivermectin 6mg http://stromectolforte.com/# ivermectin tablets dosage stromectol tabletter

  36. allegra [#]

    zyrtec 90 count price – http://allergyd.com

  37. zyrtec hives relief [#]

    fexofenadine hcl – https://allergyd.com

  38. pharmacepticacom [#]

    can i buy sildenafil over the counter https://www.pharmaceptica.com/

  39. stromectol [#]

    ivermectina en humanos https://stromectolforte.com/# invermechtin prescription drug stromectol

  40. prednisol [#]

    prednisone indications https://prednisoloneprednisolone.com/

  41. how to obtain ivermectin [#]

    ivermectin गोली लागत http://stromectolforte.com/# ivermectin tablets order stromectol 3 mg dosage

  42. bactrim [#]

    https://bactrimhoprim.com/ Trimethoprim bnf

  43. bbblicuuq [#]

    yTEYO7 ahywgdmmsplk, [url=http://kbvrqnrjgsah.com/]kbvrqnrjgsah[/url], [link=http://kyermatkxhse.com/]kyermatkxhse[/link], http://xpyldbwmhsas.com/

  44. modafinil [#]

    https://provigilandmodafinil.com/ modafinil side effects

  45. bactrim dosage [#]

    co trimoxazole dosage for adults bactrim side effects

  46. ivermectin 6 mg [#]

    Accustomed Dope Fro this outcome
    https://stromectolivermect.com ivermectin 12 mg
    https://ivermectinstrom.com ivermectin for humans
    https://ivermectstromect.com ivermectin 6 mg
    https://ivermectinstrom.com ivermectin tablets
    https://ivermectinst.com stromectol

  47. GustavoVet [#]

    readwritethink essay map
    buy college essays

CSSLab