Update: The question was edited. Both of the solutions are now equivalent.
Original answer
Yes, most notably! I don’t think the second one will work (and if it does, not very portably). The first one should be OK.
// HTML: <input id="theId" value="test" onclick="doSomething(this)" /> // JavaScript: function(elem){ var value = elem.value; var id = elem.id; ... }
This should also work.
Related Posts:
- Scroll to the top of the page using JavaScript?
- Generate pdf from HTML in div using Javascript
- Getting “TypeError: failed to fetch” when the request hasn’t actually failed
- Deleting array elements in JavaScript – delete vs splice
- How to terminate the script in JavaScript?
- Get selected value in dropdown list using JavaScript
- Accessing elements by type in JavaScript
- Clearing localStorage in javascript?
- How can I check if an element exists in the visible DOM?
- Counting the occurrences / frequency of array elements
- How to ‘minify’ Javascript code
- ++someVariable vs. someVariable++ in JavaScript
- How to check whether a Button is clicked by using JavaScript
- Get a random item from a JavaScript array
- JavaScript: IIF like statement
- How do I select text nodes with jQuery?
- Empty functions in Javascript
- Google Calendar API event insert always return 404 “not found” error
- How to add a class to a given element?
- Using getline() with file input in C++
- What does enctype=’multipart/form-data’ mean?
- await is only valid in async function
- Remove duplicate values from JS array [duplicate]
- How to read an external local JSON file in JavaScript?
- How do I remove version tracking from a project cloned from git?
- How to check if array is empty or does not exist?
- what is difference between mp4 and mpegts?
- There is no directive with “exportAs” set to “ngForm”
- How do you round to 1 decimal place in Javascript?
- Windows Activator .bat Text
- How can I add a key/value pair to a JavaScript object?
- what does a .php?id=&value=value means?
- How do I change an HTML selected option using JavaScript?
- How to print a number with commas as thousands separators in JavaScript
- Convert Array to Object
- Javascript setInterval not working
- Xilinx error: Port connections cannot be mixed ordered and named
- How to force garbage collector to run?
- Convert UTC Epoch to local date
- How to execute a JavaScript function when I have its name as a string
- How to get the ASCII value in JavaScript for the characters [duplicate]
- HTML img onclick Javascript
- Clear the cache in JavaScript
- error Unable to get property ‘display’ of undefined or null reference
- Is there a php echo/print equivalent in javascript
- How to use sed to extract substring
- getContext is not a function
- lodash multi-column sortBy
- JavaScript code not running in HTML5 document
- What is the cause for “angular is not defined”
- Unexpected token < in first line of HTML
- Running time of algorithm A is at least O(n²) – Why is it meaningless?
- ngular is automatically adding ‘ng-invalid’ class on ‘required’ fields
- How do I check if a Key is pressed on C++
- How to set “style=display:none;” using jQuery’s attr method?
- WordPress Admin Bar pushed Sticky Footer off the bottom of the page
- Javascript WP Object Documentation?
- Show only images and videos in a wp.media window
- WordPress Rest API
- Instantiate TinyMCE via JS ( rather than PHP/wp_editor )
- How to prevent loading of all plugin’s resources?
- API JSON Data in WordPress
- Creating an Exit Confirmation Popup
- Help with AJAX front end comment moderation
- Only displaying zip files with wp media
- Open div inside a custom post-type with Fancybox
- Authentication with the Rest API when using an External Application
- Save the post parent in a custom post type in Gutenberg
- Override do_item() Function to Add Extra Attribute to Scripts
- Is it possible to pass js variable to template file
- Javascript stopped working [closed]
- Is there a loading priority for login_enqueue_scripts?
- Uncaught ReferenceError: jQuery is not defined – although jQuery is loaded [closed]
- How can I import one custom block into another?
- Gutenberg Blocks: how to determine an index of the current inner block?
- WordPress theme resource won’t load over VPN
- Cannot access $wpdb, comes back NULL
- Add to cart – button should be disabled
- Dropdown menu on click change
- Send Array from JS to php file then insert it in wp database through a plugin
- How to override Plugin javascript function : $(‘body’).on(‘change’,’.class’)
- Connect / Login WordPress Hosted Website or Blog with NodeJs
- Possible way of having multiple Gutenberg instances for a page?
- Reading plugin settings in esnext wordpress block
- Hide specific category tag on single post page
- How To Tell If a Custom Field Was Made with ACF, Metabox.io, Carbon Fields, Custom Built, etc?
- Plural Forms error in Query Monitor
- show just own posts of custom-post-type to wordpress user
- How to verify that a field has a value before adding a term to a taxonomy
- Loading scripts only if a particular shortcode or widget is present
- Creating a user ‘add custom field’ section
- Javascript not working
- Facebook share button only share the_permalink(), without thumbnail, tilte, excerpt, etc
- Include Facebook Javascript SDK In WordPress
- WordPress shortcode plugin not working
- FacetWP: Plugin breaks button/modal functionality inside searchable content area
- Jquery dropdown menus working locally, but not in WordPress [duplicate]
- javscript that updates div in a single wordpress page
- How can I use AJAX in child theme template?
- WordPress enque the same script causes the setInterval not to work