Parsing of html string using jquery

None of the current answers addressed the real issue, so I’ll give it a go. var datahtml = “<html><body><div class=\”class0\”><h4>data1</h4><p class=\”class1\”>data2</p><div id=\”mydivid\”><p>data3</p></div></div></body></html>”; console.log($(datahtml)); $(datahtml) is a jQuery object containing only the div.class0 element, thus when you call .find on it, you’re actually looking for descendants of div.class0 instead of the whole HTML document that you’d … Read more

Click the poster image the HTML5 video plays?

This is working for me Andrew. In your html head add this small piece of js: var video = document.getElementById(‘video’); video.addEventListener(‘click’,function(){ video.play(); },false); Or, just add an onlick attribute directly to your html element: <video src=”https://stackoverflow.com/questions/5278262/your_video” width=”250″ height=”50″ poster=”your_image” onclick=”this.play();”/>

jquery validation: prevent form submit

You may try this (Example): $(function(){ $(“#myform”).validate(); $(“#myform”).on(‘submit’, function(e) { var isvalid = $(“#myform”).valid(); if (isvalid) { e.preventDefault(); alert(getvalues(“myform”)); } }); }); function getvalues(f) { var form=$(“#”+f); var str=””; $(“input:not(‘input:submit’)”, form).each(function(i){ str+=’\n’+$(this).prop(‘name’)+’: ‘+$(this).val(); }); return str; }

scrolltop with animate not working

You have to use $(‘html,body’) instead of $(window) because window does not have a scrollTop property. $(‘#scroll-bottom’).on(‘click’, function() { $(‘html, body’).animate({ scrollTop: 2000 }, 2000); // for all browsers // $(‘html’).animate({scrollTop: 2000}, 2000); // works in Firefox and Chrome // $(‘body’).animate({scrollTop: 2000}, 2000); // works in Safari }) #top { margin-bottom: 2000px; } <script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> … Read more

How do I use transitionend in jQuery?

The code below will trigger on the transitionend event for whatever element(s) you have in the $element variable. There are four different event names as I believe these cover all of the cross-browser inconsistencies. Replace the ‘// your event handler’ comment with whatever code you wish to run when the event is triggered. $element.on(‘transitionend webkitTransitionEnd … Read more

tech