![Logo](/_astro/logo.DNC1PCTe_Z1abT04.webp)
Enter a search term above to see results...
Enter a search term above to see results...
The DOM Manipulation methods in Query allow you to insert, remove, and modify elements in the DOM. These methods are crucial for creating dynamic and interactive user interfaces in your Semantic UI components.
Insert content to the end of each element in the set of matched elements.
$('selector').append(content)
Name | Type | Description |
---|---|---|
content | string, DOM Element, or Query object | The content to insert |
Query object (for chaining).
// Append a new paragraph to a div$('div').append('<p>New content</p>');
// Append a new button to the action buttons in a user-profile$$('user-profile').find('.action-buttons').append('<button>Follow</button>');
Insert content to the beginning of each element in the set of matched elements.
$('selector').prepend(content)
Name | Type | Description |
---|---|---|
content | string, DOM Element, or Query object | The content to insert |
Query object (for chaining).
// Prepend a new heading to a section$('section').prepend('<h2>New Section Title</h2>');
// Prepend a notification badge to the user name in a user-profile$$('user-profile').find('.user-name').prepend('<span class="badge">New</span>');
Remove the set of matched elements from the DOM.
$('selector').remove()
Query object (for chaining).
// Remove all paragraphs with a specific class$('p.outdated').remove();
// Remove the offline status indicator from a user-profile$$('user-profile').find('.status-indicator.offline').remove();
Create a deep copy of the set of matched elements.
$('selector').clone()
A new Query object containing cloned elements.
// Clone a template and append it to a containerconst $template = $('#item-template').clone();$('#container').append($template);
// Clone a user badge and append it to a list in a user-profileconst $badge = $$('user-profile').find('.user-badge').clone();$$('user-profile').find('.badge-list').append($badge);
Insert every element in the set of matched elements before the target.
$('selector').insertBefore(target)
Name | Type | Description |
---|---|---|
target | string | A selector, element, or Query object before which the content will be inserted |
Query object (for chaining).
// Insert a new paragraph before all existing paragraphs$('<p>New paragraph</p>').insertBefore('p');
// Insert a new header before the user info in a user-profile$$('<h3>User Details</h3>').insertBefore($$('user-profile').find('.user-info'));
Insert every element in the set of matched elements after the target.
$('selector').insertAfter(target)
Name | Type | Description |
---|---|---|
target | string | A selector, element, or Query object after which the content will be inserted |
Query object (for chaining).
// Insert a new paragraph after all existing paragraphs$('<p>New paragraph</p>').insertAfter('p');
// Insert a new footer after the user bio in a user-profile$$('<footer>Last updated: Today</footer>').insertAfter($$('user-profile').find('.user-bio'));
Remove the set of matched elements from the DOM, but keep all associated data and events.
$('selector').detach()
Query object containing the removed elements.
// Detach all list items, modify them, and reattachconst $items = $('ul li').detach();$items.addClass('modified');$('ul').append($items);
// Detach user posts, modify them, and reattach in a user-profileconst $posts = $$('user-profile').find('.user-posts').detach();$posts.addClass('updated');$$('user-profile').find('.posts-container').append($posts);
// Reverse the order of list items$('ul.my-list li').reverse().each((el, index) => { console.log(`Reversed order: Item ${index + 1}`);});
Creates a deep copy of the set of matched elements.
$('selector').clone()
A new Query object containing cloned elements.
// Clone a template and append it to a containerconst $template = $('#item-template').clone();$('#container').append($template);