replacewith

how to get actual content of an object after being replaceWith('something') in jquery

心已入冬 提交于 2019-12-01 03:11:05
I have this code $(document).ready(function(){ $('.selector').click(function(){ obj = $(this); obj.replaceWith('<div class="size">whats up man ??!</div>'); alert(obj.html()); }); }); I want to get the new content of 'obj' that has been 'replaceWith' but, I get the old content instead ... how do I get the actual content of 'obj' ??? my intention is to access the new 'obj' $('.selector').click(function(){ var obj = $(this), repl = $('<div class="size">whats up man ??! <span class="medium"></span></div>'); obj.replaceWith(repl); alert(obj.find('span').attr('class')); //this will print 'undefined'

how to get actual content of an object after being replaceWith('something') in jquery

余生颓废 提交于 2019-11-30 23:16:09
问题 I have this code $(document).ready(function(){ $('.selector').click(function(){ obj = $(this); obj.replaceWith('<div class="size">whats up man ??!</div>'); alert(obj.html()); }); }); I want to get the new content of 'obj' that has been 'replaceWith' but, I get the old content instead ... how do I get the actual content of 'obj' ??? my intention is to access the new 'obj' $('.selector').click(function(){ var obj = $(this), repl = $('<div class="size">whats up man ??! <span class="medium"><

New Line in Textarea to be converted to <br/>

二次信任 提交于 2019-11-29 20:22:14
There's a lot of threads here about converting br/> or preserving newlines across different languages, but not many regarding textarea. I have this script: var boxText = ""; $("textarea.BoxText").live('dblclick', function () { boxText = $(this).val().replace(/ /g, "<br/>"); $(this).replaceWith( '<div class="BoxText">' + $(this).val() + '</div>' ); }); $("div.BoxText").live('dblclick', function () { $(this).replaceWith( '<textarea form="HTML" class="BoxText">' + boxText + '</textarea>' ); }); I have a textarea element, editable. When the user double-clicks on it, it converts into a div. However

best way to write jQuery's replaceWith() in natural JavaScript

◇◆丶佛笑我妖孽 提交于 2019-11-29 00:12:40
Having trouble with a function hitting the page as soon as possible, so i need to write it in pure javascript and include it in the head. not sure how to go about it, because as i understand it, by using .replace() the new element will be moved to a different location on the page. jQuery's replaceWith() behavior is ideal. $("#imagefiles").replaceWith("<input type='file' name='imagefiles' id='imagefiles' />"); var image = document.getElementById('imagefiles'), parent = image.parentNode, tempDiv = document.createElement('div'); tempDiv.innerHTML = "<input type='file' name='imagefiles' id=

best way to write jQuery's replaceWith() in natural JavaScript

拜拜、爱过 提交于 2019-11-27 15:15:59
问题 Having trouble with a function hitting the page as soon as possible, so i need to write it in pure javascript and include it in the head. not sure how to go about it, because as i understand it, by using .replace() the new element will be moved to a different location on the page. jQuery's replaceWith() behavior is ideal. $("#imagefiles").replaceWith("<input type='file' name='imagefiles' id='imagefiles' />"); 回答1: var image = document.getElementById('imagefiles'), parent = image.parentNode,

Change the tag but keep the attributes and content — jQuery/Javascript

 ̄綄美尐妖づ 提交于 2019-11-27 08:58:26
Text changed to <p href="page.html" class="class1 class2" id="thisid">Text</p> I'm familiar with jQuery's replaceWith but that doesn't keep attributes/content as far as I know. Note: Why would p have a href ? Cuz I need to change p back to a on another event. try this: var $a = $('a#thisid'); var ahref = $a.attr('href'); var aclass = $a.attr('class'); var aid = $a.attr('id'); var atext = $a.text(); $a.replaceWith('<p href="'+ ahref +'" class="'+ aclass +'" id="'+ aid+'">'+ atext +'</p>'); Here is a more generic method: // New type of the tag var replacementTag = 'p'; // Replace all a tags with

Update div with jQuery ajax response html

半世苍凉 提交于 2019-11-26 04:47:14
问题 I am trying to update a div with the content from an ajax html response. I beleive I have the syntax correct, however the div content gets replaced with the entire HTML page response, instead of just the div selected in the html response. What am I doing wrong? <script> $(\'#submitform\').click(function() { $.ajax({ url: \"getinfo.asp\", data: { txtsearch: $(\'#appendedInputButton\').val() }, type: \"GET\", dataType : \"html\", success: function( data ) { $(\'#showresults\').replaceWith($(\'