locked
Javascript "delete value" and "delete data" instructions RRS feed

  • Question

  • User206383436 posted

    Hi,

    I have a piece of Javascript code that contains the following 2 blocks of instructions. They are part of 2 different functions. Both functions get the value of a hidden control. One function performs delete value and the other function performs delete data. I will very much appreciate if you explain what these delete operations do.

     var token = $('input[type=hidden][name=__RequestVerificationToken]', document).val();
    delete value['__RequestVerificationToken'];
    
    var token = $('input[type=hidden][name=__RequestVerificationToken]', document).val();
    delete data['__RequestVerificationToken'];

    Respectfully,
    Jorge Maldonado

    Tuesday, September 10, 2019 10:53 PM

Answers

  • User-719153870 posted

    Hi Jorge,

    JORGEMAL

    var token = $('input[type=hidden][name=__RequestVerificationToken]', document).val();

    This is a Multiple Attribute Selector, you can find some related samples here or more detailed information here.

    The 'document' is a context in jQuery selector which can  specify scope of your selector, 'document' usually means the whole current page.

    You can also see realted information when you type this syntax( $(','), the commar ) in VS, like below:

    JORGEMAL

    delete value['__RequestVerificationToken'];

    The delete method in JS is used to delete a property of one object.

    The strange thing is that in your demo, it seems in a wrong syntax. It should be object['property'] not attibute['property value']. Are you missing some code here?

    Usually, we use removeAttr() method to remove an attribute of a control.

    Hope this will help.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 11, 2019 2:26 AM

All replies

  • User-719153870 posted

    Hi Jorge,

    JORGEMAL

    var token = $('input[type=hidden][name=__RequestVerificationToken]', document).val();

    This is a Multiple Attribute Selector, you can find some related samples here or more detailed information here.

    The 'document' is a context in jQuery selector which can  specify scope of your selector, 'document' usually means the whole current page.

    You can also see realted information when you type this syntax( $(','), the commar ) in VS, like below:

    JORGEMAL

    delete value['__RequestVerificationToken'];

    The delete method in JS is used to delete a property of one object.

    The strange thing is that in your demo, it seems in a wrong syntax. It should be object['property'] not attibute['property value']. Are you missing some code here?

    Usually, we use removeAttr() method to remove an attribute of a control.

    Hope this will help.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 11, 2019 2:26 AM
  • User-474980206 posted

    you don't show enough code to know what objects value or data represent. but the code is deleting the  '__RequestVerificationToken' property of each.

    Wednesday, September 11, 2019 3:57 AM
  • User538199814 posted

    Thanks for solution. I was also searching same.

    Wednesday, September 11, 2019 6:02 AM