Wednesday, September 21, 2011

Encode HTML Characters in JavaScript using jQuery

Here's a quick post on how to encode and decode HTML characters in JavaScript using jQuery. I didn't come up with the solution, but I thought it was pretty clever.
function htmlEncode(value){
    return $('<div/>').text(value).html();
}

function htmlDecode(value){
    return $('<div/>').html(value).text();
}
Courtesy of http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding

7 comments:

  1. I was actually looking for this resource a few weeks back. Thanks for sharing with us your wisdom.This will absolutely going to help me in my projects .








    Classic Dresses
    Classic Bridesmaid Dresses
    Wedding Dresses with Sleeves

    ReplyDelete
  2. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    html5 video player

    ReplyDelete
    Replies
    1. To see WOW Gold and Buy RS Gold world in a granda of stand.And a heaven in a wild flower.Hold infinity in the palm your hand and eternity in an hour.

      Delete
  3. Thanksgiving day is around the corner. How are you going to celebrate it? You must have noticed that all places are holding promotional activities to promote sales of their products. No matter the supermarket, store or the mall, you can always get products at much cheaper prices. It is also a good choice to come to 4wowgold.com to get cheap wow gold now. Seize your time.

    ReplyDelete
  4. I was trying to use this method to encode ENdash and EMdash but this methos does not work out. can you tell how to encode them.

    ReplyDelete
  5. cialis男性朋友長期患陽痿早洩會有什麼危害viagra
    由报道:長期陽痿早洩會對男性朋友的身體和心理會造成什麼樣子的危害? 陽痿早洩的常見表現形式有哪些呢? 專家稱陽痿早洩是一種常見的性功能障礙表現威而鋼 威而鋼專賣店 犀利士 犀利士形式,很多男性都會出現這種情況,專家表示,男性如果長期患有陽痿早洩而不採取治療措施的話不僅會對正常的生活產生影響,還會引起男性不育症的發生,對男性有著極大的危害。 因此,男性朋友一定要對陽痿早洩引起重視,避免陽痿早洩給男性的生活帶來影響。
    陽痿早洩的症狀,陽痿早洩的表現體現在以下幾個方面:
    1、影響正常的性生活:男性患有陽痿早洩犀利士 犀利士專賣 犀利士哪裡買 犀利士5mg價格 壯陽藥品 犀利士專賣 威而鋼 壯陽藥 威而鋼專賣店 犀利士哪裡買後,如果沒及時的得到治療,長期下去就會使病情加重,嚴重影響到正常的性生活,使伴侶間的感情出現破裂。
    2、影響男性心理健康:男性長期患有陽痿早洩的話,就會使自己心理產生很大的負擔,還會出現抑鬱,煩躁,萎靡等多種現象,很容易使男性患有嚴重的心理疾病,從而影響了男性的心理健康。
    3、影響男性的生育:男性患有陽痿早洩後,會使陰莖難以勃起,令精子無法進入女性的子宮,不能與卵子正常結合,從而影響了男性的生育能力。
    陽痿早洩會影響患者的性生活,這一點是非常明確的,而且還會影響家庭。 陽痿早洩的危害可以分為三個等級,分別為:輕度陽痿早洩、中度陽痿早洩和重度陽痿早洩,輕度陽痿早洩患者,常見症狀是勃起不堅,可以委曲完成性生活,但此時患者的生理性能處於非健康的狀態,威而鋼哪裡買 犀利士哪裡買 壯陽藥品 壯陽藥 威而鋼哪裡買 犀利士專賣 威而鋼 威而鋼哪裡買 威而鋼專賣店 威而鋼藥局精子質量較差,不能保證育出健康的小生命。 而對重度陽痿早洩患者,是無法完成的,從而使得精子無法輸入與卵子相結合,從而無法完成受孕過程,終極影響生養能力。 這的對於希望有自己愛情結晶的夫婦無疑不是一個毀滅性的打擊,所以針對於男性陽痿早洩的情況,請及時的問診就醫,早點治療好,避免陽痿早洩對於自身的危害。

    ReplyDelete