Introducing some Jquery functions that affect HTML tags for students.

Tram Ho

Preface.

Today I’m talking about using some functions that affect html tags in jquery. I hope this article can be helpful for students who are new to jquery.

1, Append () function.

-The append () function in Jquery works to insert content into the back of the component to impact.
Syntax:
$('selector').append(content); In it: content is the content that you need to add.

For example:
$('p').append('<b>Toidicode.com</b>');

demo

2, The prepend () function.

-The prepend () function in Jquery works to insert content into the beginning of the component to impact.

Syntax:

$('selector').prepend(content); In it: content is the content that you need to add.

For example:

$('p').prepend('<b>Toidicode.com</b>, ');

demo

3, After () function.

-The after () function in Jquery works to insert content into the back of the component to impact.

Syntax:

$('selector').after(content); In it: content is the content that you need to add.

For example:

$('p').after('<div style="background:red;">Toidicode.com</div>'); demo

4, Before () function.

-The before () function in Jquery works to insert content into the front of the component that needs impact.

Syntax:

$('selector').before(content); In it: content is the content that you need to add.

For example:

$('p').before('<div style="background:red;">Toidicode.com</div>');

demo

5, The function empty ().

-The empty () function in Jquery works to empty the content of the component that needs impact.

Syntax:

$('selector').empty(); For example:

$('p').empty(); demo

6, The remove () function.

-The remove () function in Jquery has the effect of deleting the selected components.

Syntax:

$('selector').remove(argument); Inside:

If the remove () function is left blank, it clears all the components within the selected component.
If you want to delete specific components, just list the components to delete in the remove () function.
Example: Delete all tags p.

$('p').remove(); demo

Example: Delete all p tags whose class is ‘demo’.

$('p').remove('.demo'); demo

Example: Delete all p tags whose class is ‘demo’ or id is ‘des’.

$('p').remove('.demo, #des'); demo

7, Conclusion

So I have introduced through 8 functions that affect HTML tags. I think it is very useful for those new to Jquery. Thank you for your interest in your article.

Share the news now

Source : Viblo