HTML   &lt;div id='story'&gt;         &lt;div class='item folder'&gt;sky&lt;/div&gt;     &lt;div class='item folder'&gt;sea&lt;/div&gt;  &lt;/div&gt;   JS    $(".item").on('click', function(){     $('.marked').removeClass('marked');     $(this).addClass('marked'); });   This works but now the the content of #story is replaced using ajax procedure:  ...     success: function(data) {     $('#story').html(data); }   And the new content is:    &lt;div class='item folder'&gt;earth&lt;/div&gt; &lt;div class='item folder'&gt;venus&lt;/div&gt;    And here on('click', function() doesn't work. Classes are not removed/added.
112
I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.  This happens on page ready and works just fine.  The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound.  I have found this plugin (), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option.
80948
I have an HTML page with a typical structure:  &lt;html&gt;   &lt;head&gt;    &lt;script src="..." &gt;&lt;/script&gt;    &lt;style&gt;...&lt;/style&gt;   &lt;/head&gt;   &lt;body&gt;    content   &lt;/body&gt;   &lt;script&gt;     var success_callback = function(data) {       // REPLACE PAGE CONTENT &amp; STRUCTURE WITH "data"     }     ajax(url, params, success_callback);   &lt;/script&gt; &lt;/html&gt;   Do you think it is possible ?  I've already tried to give the html tag an id and doing $(id).replace(data); with no success.  Don't ask me why, but that is what I need (I'm working with a special "mashup builder" site... it is a long story).  EDIT : I forgot to say that scripts in the received content have to be executed, even external scripts included using &lt;script src="..."&gt;.
84374
I’ve had a good look and can’t seem to find out how to select all elements matching certain classes in one jQuery selector statement such as this:  $('.myClass', '.myOtherClass').removeClass('theclass');   Any ideas on how to achieve this? The only other option is to do  $('.myClass').removeClass('theclass'); $('.myOtherClass').removeClass('theclass');   But I’m doing this with quite a few classes, so it requires much code.
19020
One screenshot will explain it the best:    It shouldn't be there - appeared right after posting the comment. When reloading the page it disappears so something goes awry with the AJAX handling.  Clicking it is reloading the existing comment(s) and open the new comment text box.
3010
I have created a panel page (i.e using panels). I can add html content to it from the panel itself using add content->New custom content. I can also add css classes (add body css classes).  Now I would like to add a jquery button to that panel page. I could add a javascript to my theme but then it would be called on every page load not only this specific panel-page. So I would like to add my javascript through my module.   But how do I programatically check that the current page beeing viewed is that specific page panel? Is there a hook that lets me check that?  Thanks,  baba
74429
I want to disable the hyperlink for a specific class part of Site Feeds in SharePoint 2013.  I`m using Jquery to do the same, but it is not working for me. Code for reference  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt;     var location= $('.ms-microfeed-userName ms-textLarge ms-subtleLink').attr("href");  $(".ms-microfeed-userName ms-textLarge ms-subtleLink").removeAttr('href');  $('ul').addClass('expanded');  $('ul.expanded').fadeIn(300);  $(".ms-microfeed-userName ms-textLarge ms-subtleLink").attr("href", location);    &lt;/script&gt;
88861
I don't want to use jQuery, but I'd like to use Ajax to do file uploading. Is that possible?  If so, where can I find information/tutorial on it?
29285
What's the difference between &lt;div class=""&gt; and &lt;div id=""&gt; when it comes to CSS? Is it alright to use &lt;div id=""&gt;?  I see different developers doing this in both ways, and since I'm self taught, I've never really figured it out.
103418
HTML  more code here...  &lt;script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="https://example.com/sites/all/modules/ac_modules/ac_exercise/ac_exercise.js?nkuo2r"&gt;&lt;/script&gt;   more code here...  &lt;div class="form-item form-type-textfield form-item-time-start"&gt;   &lt;label for="edit-time-start"&gt;Time Start &lt;/label&gt;  &lt;input type="text" id="edit-time-start" name="time_start" value="11:28:12" size="4" maxlength="8" class="form-text" /&gt; &lt;/div&gt;   more code here...  Javascript - ac_exercise.js  $(document).ready(function(){    $("#edit-time-start").on("change paste keyup", function() {      alert($(this).val());    }); });   In Chrome's console I get the following error: Uncaught TypeError: undefined is not a function - ac_exercise.js?nkuo2r:1 which is this line of code:  $(document).ready(function(){
44255
I am trying to insert a chunk of HTML into a div. I want to see if plain JavaScript way is faster than using jQuery. Unfortunately, I forgot how to do it the 'old' way. :P  var test2 = function(){     var cb = function(html){         var t1 = document.getElementById("test2");         var d = document.createElement("div");         d.id ="oiio";         d.innerHtml = html;         t1.appendChild(d);         console.timeEnd("load data with javascript");     };     console.time("load data with javascript");     $.get("test1.html", cb); }   what am i doing wrong here guys?  edit:  Someone asked which is faster, jquery or plain js so i wrote up a test:   plain js is 10% faster
27208
I have an HTML string representing an element: '&lt;li&gt;text&lt;/li&gt;'. I'd like to append it to an element in the DOM (a ul in my case). How can I do this with Prototype or with DOM methods?  (I know i could do this easily in jQuery, but unfortunately we're not using jQuery.)
72166
I have some HTML and jQuery that slides a div up and down to show or hide` it when a link is clicked:  &lt;ul class="product-info"&gt;   &lt;li&gt;     &lt;a href="#"&gt;YOU CLICK THIS TO SHOW/HIDE&lt;/a&gt;     &lt;div class="toggle"&gt;       &lt;p&gt;CONTENT TO SHOW/HIDE&lt;/p&gt;     &lt;/div&gt;   &lt;/li&gt; &lt;/ul&gt;   $('div.toggle').hide(); $('ul.product-info li a').click(function(event){   $(this).next('div').slideToggle(200); }   My question is: How do I use preventDefault() to stop the link acting as a link and adding "#" to the end of my URL &amp; jumping to the top of the page?  I can't figure out the right syntax, I just keep getting an error saying      preventDefault() is not a function.
67914
I am creating an element with document.createElement(). Now how can I pass it to a function that only takes a Jquery object?  $("#id")    I can not use it, as the element has not been rendered in the page yet.
116918
When using divs when is it best to use a class vs id?   Is it best to use class, on say font variant or elements within the html? Then use id for the structure/containers?   This is something I've always been a little uncertain on, any help would  be great.
20484
Recently I've been doing a lot of modal window pop-ups and what not, for which I used jQuery. The method that I used to create the new elements on the page has overwhelmingly been along the lines of:   $("&lt;div&gt;&lt;/div&gt;");   However, I'm getting the feeling that this isn't the best or the most efficient method of doing this. What is the best way to create elements in jQuery from a performance perspective?   has the benchmarks to the suggestions below.
32885
I have some html like this:  &lt;div id="1"&gt;     &lt;p&gt;         Volume = &lt;input type="text" /&gt;         &lt;button rel="3.93e-6" class="1" type="button"&gt;Check answer&lt;/button&gt;     &lt;/p&gt;     &lt;div&gt;&lt;/div&gt; &lt;/div&gt;   and some JS like this:  $("button").click(function () {     var buttonNo = $(this).attr('class');     var correct = Number($(this).attr('rel'));      validate (Number($("#"+buttonNo+" input").val()),correct);     $("#"+buttonNo+" div").html(feedback); });   What I'd really like is if I didn't have to have the class="1" on the button (I know numeric classes aren't valid, but this is a WIP!), so I could determine buttonNo based on the id of the parent div. In real life there are multiple sections looking like this.   How do I find the id of the div parenting the button. What would be a more semantic way to store the answer in the button code. I want to make this as foolproof as possible for a non programmer to copy and paste without breaking things!
105050
I want to write a script that completely removes every instance of a particular span class from a given HTML file.   For example, if my undesired span class is "foo" then running my script on the file  &lt;html&gt;   &lt;head&gt;     &lt;title&gt;hello world&lt;/title&gt;   &lt;/head&gt;   &lt;body&gt; lorem ipsum &lt;span class="foo"&gt; STUFF &lt;/span&gt; alpha beta &lt;span class="foo"&gt; MORE  STUFF&lt;/span&gt;   &lt;/body&gt; &lt;/html&gt;   should yield  &lt;html&gt;   &lt;head&gt;     &lt;title&gt;hello world&lt;/title&gt;   &lt;/head&gt;   &lt;body&gt; lorem ipsum alpha beta    &lt;/body&gt; &lt;/html&gt;   I have two questions.   Can this be done with sed or perl?  Is there a tool in linux that is designed to easily edit HTML documents like this?