Đây là một tệp html mẫu có nút gửi. Bây giờ hãy sửa đổi kiểu của đoạn văn bản thông qua mã javascript
Tệp HTML mẫu
JS DOM paragraph style
JavaScript Exercises - w3resource
Style
Lời khuyên. Nhấp vào nút, phông chữ, cỡ chữ và màu sắc của đoạn văn bản sẽ được thay đổi
Giải pháp mẫu. -
Mã HTML
JS DOM paragraph style
JavaScript Exercises - w3resource
Style
Mã JavaScript
function js_style[]
{
//font styles added by JS:
text.style.fontSize = "14pt";
text.style.fontFamily = "Comic Sans MS";
text.style.color = "green";
}
Đầu ra mẫu
, , , , ,, , and . It means we cannot apply the title event on the given tags.
In HTML, we can use the title attribute and assign a JavaScript function to it. We can also use the JavaScript's addEventListener[] method and pass a click event to it for greater flexibility.
Syntax
Now, we see the syntax of using the title event in HTML and in javascript [without addEventListener[] method or by using the addEventListener[] method].
In HTML
In JavaScript
In JavaScript by using the addEventListener[] method
Let's see how to use title event by using some illustrations. Now, we will see the examples of using the title event in HTML, and in JavaScript.
Example1 - Using title attribute in HTML
In this example, we are using the HTML title attribute and assigning a JavaScript's function to it. When the user clicks the given button, the corresponding function will get executed, and an alert dialog box will be displayed on the screen.
Test it NowOutput
Output
Test it NowOutput
On clicking the text Click me, the output will be -
Làm thế nào JavaScript có thể được sử dụng để sửa đổi nội dung của một đoạn văn?
element with id="p1".