JavaScript Removal of multiple fields and labels

I'm very new to jQuery and have been stumped by particular issue. I am dynamically adding 2 checkbox fields to a screen form using the code below:

var summon_search = "<br><br><br><label for='summon_search'>Search this resource from compatible products*</label><input type='checkbox' id='summon_search' >";
var summon_link = "<br><br><label for='summon_link'>Link direct from content items in compatible products*</label><input type='checkbox' name='summon_link'>";
$(summon_search+summon_link).insertAfter("#jstor_selection");

However I have had limited success when I want to remove these fields AND labels (which is dependant on another value) and replace them with new fields. The code below shows my best attempt so far. It does appear to remove the labels and first field, but for some reason the last field remains. Could someone please advise if they can spot anything I've done wrong, or perhaps supply a better example of handling this ?

if ($("#summon_search").length > 0 ) { 
    //Removal of Label and Field (Attempted) 
    $("label[for=summon_search]").remove();
    $("label[for=summon_link]").remove();
    $("#summon_search").remove();
    $("#summon_link").remove();

Any feedback much appreciated.

Answer:1

Change name='summon_link' to id='summon_link', because #summon_link expects an id.

Answer:2

if you see your code the summon_link variable give it a id instead of name like in the summon_search variable


 name=summon_link change it to id='summon_link' 

Answer:3

if your intention is to add these HTML string after object with Id 'jstor_selection', you can use like this

$("#jstor_selection").append(summon_search+summon_link);
Answer:4

<canvas id="c" name="c"></canvas> <input style="display:none;" type="file" name="nextImage" id="nextImage"/> Above code is canvas where edited image is placed, below is input field ...

<canvas id="c" name="c"></canvas> <input style="display:none;" type="file" name="nextImage" id="nextImage"/> Above code is canvas where edited image is placed, below is input field ...

function findLongestWordLength(str) { var res = str.split(" "); var ar = []; for (let i = 0; i < res.length; i++) { let leength = res[i].length; ar.push(leength); //ar ...

function findLongestWordLength(str) { var res = str.split(" "); var ar = []; for (let i = 0; i < res.length; i++) { let leength = res[i].length; ar.push(leength); //ar ...

  1. find length of the largest region in boolean matrix
  2. find the length of largest subarray with 0 sum
  3. find the length of largest pole
  4. find the length of longest palindrome in a string

I am using ASP.NET MVC 3, I want to upload a image file using an ajax form My Index view code is: <% using (Ajax.BeginForm("Save","Home", new AjaxOptions() { HttpMethod = "POST", InsertionMode = ...

I am using ASP.NET MVC 3, I want to upload a image file using an ajax form My Index view code is: <% using (Ajax.BeginForm("Save","Home", new AjaxOptions() { HttpMethod = "POST", InsertionMode = ...

I am facing a problem in Google map marker clustering. I am using api v3, but due to some reasons, which I am not able to figure out, I cannot apply marker clustering. I'd be thankful for any help and ...

I am facing a problem in Google map marker clustering. I am using api v3, but due to some reasons, which I am not able to figure out, I cannot apply marker clustering. I'd be thankful for any help and ...

  1. google marker clusterer plus
  2. google marker cluster options
  3. google marker cluster images
  4. google marker cluster color
  5. google marker cluster infowindow
  6. google maps marker cluster
  7. google map marker cluster tutorial
  8. google map marker cluster tutorial android
  9. google maps marker cluster options
  10. google map marker cluster same location
  11. google maps marker cluster demo
  12. google maps marker clustering example
  13. google map marker cluster click event
  14. google map marker cluster infowindow
  15. google maps marker cluster color
  16. google maps marker cluster icons