
M4Q html, text, value
Set and retrieve html, text and value for elements.
html()
Set and get element innerHtml
property.
You can get innerHtml
property for first element in matched set, and set it to each element in set with function html()
.
If argument is a m4q
object, will be used outerHtml
<div>This a example text</div>
<ul id="list">
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
<li>list item 4</li>
<li>list item 5</li>
<li>list item 6</li>
</ul>
var div = $("div");
console.log(div.html()); // Get div innerHtml
div.html("<p>New html</p>"); // Set div innerHtml
div.html($("#list")); // copy ul into div
div.html(""); // clear div innerHtml
outerHTML()
Get outerHTML
element property.
<div>This a example text</div>
console.log( $("div").outerHTML() ); // Outputs: "<div>This a example text</div>"
text()
Get and set textContent
element property.
<div>This a example text</div>
console.log( $("div").text() ); // Outputs: "This a example text"
$("div").text("Other text"); // Set textContent for div
innerText()
Get and set innerText
element property.
<div>This a example text</div>
console.log( $("div").innerText() ); // Outputs: "This a example text"
$("div").innerText("Other text"); // Set innerText for div
val()
Get and set value
element property. You can use this method with input element and textarea. If element not supported value
property, the function action will not have a result.
<input id="inp" type="text" value="This is a input value">
console.log( $("#inp").val() ); // Outputs: "This a input value"
$("#inp").val("123"); // Now input has value 123
empty()
Clear element innerHTML
property.
<div>This a example text</div>
$("div").empty(); // Now div is: <div></div>