Safari / JQUery - Insert and update a hidden field on a page

In Safari, I try to insert a hidden field in the DOM and then update its value as shown below.

colHiddenFieldId = 'row_100000_0_NewValue' $("#" + colHiddenFieldId).val('TEST') 

However, the value is never set, it seems that Safari does not believe that the hidden field exists. I know that it works because it works on any other browser known to man!

Is it really bad to do in a safari book?

0
source share
2 answers

Are you sure you are missing the “0” in the title, or maybe too much? You can see if Safari has access to it, moving through all hidden fields and warning their identifier:

Assuming the field already exists ...

 $("input[type='hidden']").each(function(){ alert($(this).attr("id")); }); 

Creating a field ...

 var myId = "someIdHere"; $("<input />") .attr("type","hidden") .attr("id",myId) .val("Something") .appendTo("body"); 
+3
source

It doesn't look like you are creating a hidden field - unless you have left this part of your code.

You need something like this:

 // set the name of the hidden field var colHiddenFieldId = 'foo'; // create the hidden field (insert it) $("#yourForm").append("<input type='hidden' id='" + colHiddenFieldId + "' name='" + colHiddenFieldId + "' value='TEST' />"); 

If you take a different approach to inserting a hidden field, this may help to publish this code as well.

+2
source

Source: https://habr.com/ru/post/1415646/


All Articles