How can I know which radio button is selected via jQuery? You can move if (!equal) return false; down to the bottom of $.each to avoid firing the function again. Content available under a Creative Commons license. HTML: /echo/html/ It returns, See the comment below by @R-U-Bn. How to append HTML code to a div using JavaScript ? rev2023.3.3.43278. How do I refresh a page using JavaScript? It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. Given an HTML document containing two elements and the task is to check whether both elements are same or not with the help of JavaScript. . The best answer I could find for how to do that in a jQuery way was by none other than John Resig here on SO! That means one object is strictly equal I put an alert inside this condition it showed up. Not the answer you're looking for? How to make div width expand with its content using CSS ? Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. How to compare two objects to determine the first object contains equivalent property values to the second object in JavaScript ? Why does Mister Mxyzptlk need to have a weakness in the comics? I've lately come to understand that although return stops the execution of the code after itself inside the each loop, it does not prevent the code from executing after the each block. This solution worked for me: I don't think there's a good "jQuery " way to do this, but if you need efficiency, map one of the arrays by a certain key (one of the unique object fields), and then do comparison by looping through the other array and comparing against the map, or associative array, you just built. 1. What is the most efficient way to deep clone an object in JavaScript? Thanks. Every time you call the jQuery() function, a new object is created and returned. So even equality checks on the same selectors will fail.