profile
viewpoint

Ask questionsMethod scrollLeft not registered

In jsfiddle.net, if I add the following code to the HTML segment of the page:

<script type="text/javascript">
 function scrollLeft() {
     console.log('left');
 }
  
 function scrollRight() {
     console.log('right');
 }
</script>

<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>

<button onclick="scrollLeft()">
  Left
</button>
<button onclick="scrollRight()">
  Right
</button>

I get the following error when clicking the left button:

?editor_console=true:113 Uncaught TypeError: scrollLeft is not a function
    at HTMLButtonElement.onclick (?editor_console=true:113)
onclick @ ?editor_console=true:113

This is kinda weird. If I rename 'scrollLeft' to 'left' for example then the function works. Apparently there's a bug somewhere internally in JSFiddle where it doesn't allow that specific function to be registered.

jsfiddle/jsfiddle-issues

Answer questions oskarkrawczyk

You're trying to overwrite a native method: https://developer.mozilla.org/pl/docs/Web/API/Element/scrollLeft

Closing. Not a JSFiddle issue.

useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List