In this article, we will see how to find the title attribute of the first emphasized on the page using jQuery. The title is an attribute, not an element that is a part of the head element. Emphasized is an element that is used to give more importance to that text.
Method/function used –
- .click(): This method triggers the click event to run when a click event occurs.
- .attr(): It is used to get the value of an attribute for the first element in the set of matched elements.
- .text(): It is used to get the combined text contents of each element in the set of matched elements, including their descendants.
Example 1: In the following examples first, we will find the emphasized element and print the title value after clicking the button.
Output: The text present in the paragraph and the emphasized element gets displayed followed by the button. After clicking the button you can see the text(value) present in the title attribute.