Category: javascript
dom manipulation with jquery
Published on 30 Sep 2026
Explanation
The text() method gets or changes the text content of an element.
Code:
$('#title').text('New Title');
const value = $('#title').text();
Explanation
The html() method gets or changes the HTML content inside an element.
Code:
$('#content').html('<b>Hello</b>');
Explanation
The val() method gets or changes the value of form elements.
Code:
$('#username').val('Praveen');
const name = $('#username').val();
Explanation
The attr() method can read or modify HTML attributes.
Code:
$('#profile').attr('href', '/profile');
const url = $('#profile').attr('href');
Explanation
jQuery provides methods such as append(), prepend(), remove(), and empty() for modifying the DOM.
Code:
$('#list').append('<li>New Item</li>');
$('#list').prepend('<li>First Item</li>');
$('#old').remove();