0

I'm currently developing an webextension for Chrome and Fiferox. I'm loading some Html content using a get request and I need to change one of the inputs values in the HTML data response before insert in the DOM.

Here is a part of the relevant code:

var url = browser.extension.getURL("resources/forms/form-a.html");
$.get(url, function(data){

 $(data).find("input[id='name:front']").val("New Value");

 //Here the console output is NOT "New Value"
 console.log($(data).find("input[id='name:front']").val())

 $("#form-names").replaceWith($(data));

});

I hoping to change some inputs values before replacing the DOM content. Some ideas ??

Thanks in advance.

4
  • Here is a part of the relevant code - is this your webextension? Commented May 3, 2018 at 1:26
  • no really, my webextension do a lot of other things but my question is how I can change the input value for replace the HTML content of the page. Need more info ?
    – Alks
    Commented May 3, 2018 at 1:31
  • so, that code is not part of the webextension? (I'm trying to get a handle on what you're asking) Commented May 3, 2018 at 1:34
  • yes, that code is in the content script of my webextension.
    – Alks
    Commented May 3, 2018 at 1:35

1 Answer 1

1

Each time you call $(data) you are parsing the response and creating new HTML elements (docs). If you saved the elements, changed the value, then updated your DOM you'll find it works OK.

var url = browser.extension.getURL("resources/forms/form-a.html");
$.get(url, function(data){

  var newForm = $(data);
  newForm.find("#name:front").val("New Value");

  // Here the console output is should be "New Value"
  console.log(newForm.find("#name:front").val())

  $("#form-names").replaceWith(newForm);
});
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.