Hướng dẫn convert text to innerhtml

I want to change the Button' value with a font awesome spinning animation icon on click.

HTML:




  

Script:

function abc(this1)
{
  //alert('asdasd');
  this1.disabled=true; 
  this1.value ='';

}

This one only replaces the Button's value with a non-working html code. I tried it with:

document.getElementById('button_g').innerHTML = '';

But doesn't work. Please advise.

asked Jul 18, 2021 at 4:29

Instead of input you should use button and set innerHTML of button

function abc(this1) {
  this1.disabled = true;
  this1.innerHTML = '';

}
button {
  padding: .25rem .75rem;
  border: 1px solid #3d3a37;
  border-radius: 6px
}




answered Jul 18, 2021 at 4:34

Hướng dẫn convert text to innerhtml

DecPKDecPK

23k5 gold badges20 silver badges39 bronze badges

4

The value attribute has a different meaning for each type of the input tag. Yours is a button and so the value attribute is linked to the text inside the button, not the inner html of it.

If you want to change the inner html, use this1.innerHtml

For more read here

answered Jul 18, 2021 at 4:35

Hướng dẫn convert text to innerhtml

Not the answer you're looking for? Browse other questions tagged javascript html jquery font-awesome or ask your own question.

Chuyển đổi Text đến HTML tập tin trực tuyến miễn phí. Mạnh mẽ Free Online Text đến HTML chuyển đổi tài liệu rất dễ dàng. Không yêu cầu cài đặt phần mềm máy tính như Microsoft Word, OpenOffice hoặc Adobe Acrobat. Tất cả chuyển đổi bạn có thể thực hiện trực tuyến từ bất kỳ nền tảng nào: Windows, Linux, macOS và Android. Chúng tôi không yêu cầu đăng ký. Công cụ này hoàn toàn miễn phí.
Về trợ năng, bạn có thể sử dụng các công cụ chuyển đổi Text đến HTML trực tuyến của chúng tôi để xử lý các định dạng tệp và kích cỡ tệp khác nhau trên bất kỳ hệ điều hành nào. Cho dù bạn đang sử dụng MacBook, máy Windows hay thậm chí là một thiết bị di động cầm tay, bộ chuyển đổi Text đến HTML luôn sẵn sàng trực tuyến, để thuận tiện cho bạn.

Chuyển đổi nhanh và dễ dàng

Tải lên tài liệu của bạn, chọn loại định dạng lưu và nhấp vào nút “Chuyển đổi”. Bạn sẽ nhận được liên kết tải xuống ngay sau khi tập tin được chuyển đổi.

Chuyển đổi từ mọi nơi

Nó hoạt động từ tất cả các nền tảng bao gồm Windows, Mac, Android và iOS. Tất cả các tập tin được xử lý trên máy chủ của chúng tôi. Không cần cài đặt plugin hoặc phần mềm cho bạn.

Chất lượng chuyển đổi

Được cung cấp bởi Aspose.PDF . Tất cả các tập tin được xử lý bằng API Apose, đang được nhiều công ty Fortune 100 trên 114 quốc gia sử dụng.

The Element property innerHTML gets or sets the HTML or XML markup contained within the element.

To insert the HTML into the document rather than replace the contents of an element, use the method insertAdjacentHTML().

Value

A string containing the HTML serialization of the element's descendants. Setting the value of innerHTML removes all of the element's descendants and replaces them with nodes constructed by parsing the HTML given in the string htmlString.

Exceptions

SyntaxError DOMException

Thrown if an attempt was made to set the value of innerHTML using a string which is not properly-formed HTML.

NoModificationAllowedError DOMException

Thrown if an attempt was made to insert the HTML into a node whose parent is a Document.

Usage notes

The innerHTML property can be used to examine the current HTML source of the page, including any changes that have been made since the page was initially loaded.

Reading the HTML contents of an element

Reading innerHTML causes the user agent to serialize the HTML or XML fragment comprised of the element's descendants. The resulting string is returned.

let contents = myElement.innerHTML;

This lets you look at the HTML markup of the element's content nodes.

Note: The returned HTML or XML fragment is generated based on the current contents of the element, so the markup and formatting of the returned fragment is likely not to match the original page markup.

Replacing the contents of an element

Setting the value of innerHTML lets you easily replace the existing contents of an element with new content.

Note: This is a security risk if the string to be inserted might contain potentially malicious content. When inserting user-supplied data you should always consider using Element.SetHTML() instead, in order to sanitize the content before it is inserted.

For example, you can erase the entire contents of a document by clearing the contents of the document's body attribute:

document.body.innerHTML = "";

This example fetches the document's current HTML markup and replaces the "<" characters with the HTML entity "<", thereby essentially converting the HTML into raw text. This is then wrapped in a

 element. Then the value of innerHTML is changed to this new string. As a result, the document contents are replaced with a display of the page's entire source code. 

document.documentElement.innerHTML = `
${document.documentElement.innerHTML.replace(/</g,"<")}
`
;

Operational details

What exactly happens when you set value of innerHTML? Doing so causes the user agent to follow these steps:

  1. The specified value is parsed as HTML or XML (based on the document type), resulting in a DocumentFragment object representing the new set of DOM nodes for the new elements.
  2. If the element whose contents are being replaced is a