javascript - Completly remove a tag from the source - Stack Overflow

I would like to remove a tag with the class of '.de'.$('.de').remove(); will remove

I would like to remove a tag with the class of '.de'.

$('.de').remove(); will remove it from the page but when I check the source code, then I still see the tag.

The problem that I have is, the following tag needs to be removed from the form, otherwise it will get sent and that's not what I want.

<input class="input_field_left de" name="friend_vorname[]" type="text" placeholder="Vorname">

Or maybe there is another way to not let this field get sent?!

I would like to remove a tag with the class of '.de'.

$('.de').remove(); will remove it from the page but when I check the source code, then I still see the tag.

The problem that I have is, the following tag needs to be removed from the form, otherwise it will get sent and that's not what I want.

<input class="input_field_left de" name="friend_vorname[]" type="text" placeholder="Vorname">

Or maybe there is another way to not let this field get sent?!

Share Improve this question asked Jan 5, 2016 at 8:19 Pom CanysPom Canys 3792 gold badges5 silver badges16 bronze badges 2
  • 2 $('.de').remove(); will remove all the matched elements including those in the form. How can then it be sent to server on form submission? – Tushar Commented Jan 5, 2016 at 8:20
  • What exactly are you planning to do? Do you have a form with multiple languages but only want to have the chosen one to be shown? If yes, why don't you create the form dynamically, instead of hardcoding the form and trying to remove the redundant inputs? – Marv Commented Jan 5, 2016 at 8:22
Add a ment  | 

2 Answers 2

Reset to default 9

This is just how "view source" works in browsers. It shows you what came from the server (and usually re-queries it from the server [which may read it from cache]), not what is currently in the page.

To see what's currently in the page, you need to use the "Elements" or "DOM" tab in your browser's dev tools (usually opened via F12 or Ctrl+Shift+I). You can usually open it and move to a specific element by right-clicking that element on your page and choosing "Inspect element", so if you do that with your form after your $('.de').remove(); is run, you'll see the form without the .de elements in it.

The problem that I have is, the following tag needs to be removed from the form, otherwise it will get sent and that's not what I want.

No, it won't. Your $('.de').remove(); will remove any matching elements from the page, and they will not be submitted with the form if the form is then submitted.

You cannot delete a tag from source code with j Query if you want to do that try to add the tag with jQuery.(Dynamically created tags or elements only can be removed dynamically using jQuery.)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744245609a4564912.html

相关推荐

  • javascript - Completly remove a tag from the source - Stack Overflow

    I would like to remove a tag with the class of '.de'.$('.de').remove(); will remove

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信