Skip to content
Advertisement

Javascript Dynamic Data binding code not working

I am writing code that uses data binding to change the innerHTML of an span to the input of the user, but I can’t get it to work. What it should do is show the input on the right side of the input field on both the input fields, but it doesn’t. Can someone please help me out.

HTML:

JavaScript

Javascript:

JavaScript

https://jsfiddle.net/Mauro0294/g3170whc/4/

Advertisement

Answer

I made some changes to the fiddle to get the desired result. The problem was with your logic to refer the elements using the dataset attributes, so I tried to simplify it.

Some notable changes :

  1. Updated the data-bit to use lastName instead of LastName. Made it same as your state.
  2. Used getAttribute to get the value of the data-* properties to correctly get the reference.

I think this is what you’re looking for:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement