jquery-after

Why does jQuery .after() not chain the new element?

末鹿安然 提交于 2019-12-29 08:27:10
问题 I am curious why jQuery's .after() does not chain, or "provide you with," the new element that you create with it. It seems to me like it should, but I am no expert and was hoping someone could shed some light on why it's a bad idea. Here's an example to see what I would like from .after(): Here is some markup: <div id="content1"> <p id="hello1">Hello</p> </div> <div id="content2"> <p id="hello2">Hello</p> </div> Here's what I want, but this replaces "Hello" with "World!": $('#hello1').after(

jquery reset after()

倾然丶 夕夏残阳落幕 提交于 2019-12-11 09:05:10
问题 is there a way to reset/update an after() element? Not add another after() text. Thank you 回答1: Does after have a callback parameter? If so you can use that to call a function with what you'd want to do. 回答2: Your question is not clear. I'll asume you want to modify an element added with .after() Instead of doing this: $("#elem1").after('<div id="after />"); You could do this (use insertAfter ) $('<div id="after" />').insertAfter("#elem1").attr("width", 200).html("hi") ...; Hope this helps.

jQuery: What's the difference between after() and insertAfter()

柔情痞子 提交于 2019-12-03 04:04:39
问题 jQuery has an .after() method, and also an .insertAfter() method. What's the difference between them? I think I can use .after() to insert elements after a selected element (or elements). Is that right? What's .insertAfter() for? 回答1: They are mutual opposites. ' after ' inserts the argument after the selector. ' insertAfter ' inserts the selector after the argument. Here is an example of the same thing done with: insertafter(): <div class="container"> <h2>Greetings</h2> <div class="inner"

Using .after() to add html closing and open tags

ⅰ亾dé卋堺 提交于 2019-11-27 05:29:56
I'm trying to split an unordered list into two columns by finding the halfway point of the list and adding </ul><ul> after that </li> . This could be the complete wrong way to do this but it is how I thought to do it. My js looks like this: $('.container ul').each(function(){ var total = $(this).children().length; var half = Math.ceil(total / 2) - 1; $(this).children(':eq('+half+')').after('</ul><ul>'); }); The problem I'm having and what I don't understand is that .after() is reversing the order of the tags and outputs: <ul> <li><a href="#">link</a></li> <li><a href="#">link</a></li> <li><a

.append(), prepend(), .after() and .before()

天涯浪子 提交于 2019-11-26 23:14:27
I am pretty proficient with coding, but now and then I come across code that seems to do basically the same thing. My main question here is, why would you use .append() rather then .after() or vice verses? I have been looking and cannot seem to find a clear definition of the differences between the two and when to use them and when not to. What are the benefits of one over the other and also why would i use one rather then the other?? Can someone please explain this to me? var txt = $('#' + id + ' span:first').html(); $('#' + id + ' a.append').live('click', function (e) { e.preventDefault(); $

Using .after() to add html closing and open tags

☆樱花仙子☆ 提交于 2019-11-26 12:48:03
问题 I\'m trying to split an unordered list into two columns by finding the halfway point of the list and adding </ul><ul> after that </li> . This could be the complete wrong way to do this but it is how I thought to do it. My js looks like this: $(\'.container ul\').each(function(){ var total = $(this).children().length; var half = Math.ceil(total / 2) - 1; $(this).children(\':eq(\'+half+\')\').after(\'</ul><ul>\'); }); The problem I\'m having and what I don\'t understand is that .after() is

jQuery: Add element after another element

社会主义新天地 提交于 2019-11-26 08:48:33
问题 I have a certain textbox and I want to add a div after it. I\'ve tried the .append() function, but that only adds the div in the element. For example, I have: <input type=\"text\" id=\"bla\" /> and I want to change that into: <input type=\"text\" id=\"bla\" /><div id=\"space\"></div> 回答1: try using the after() method: $('#bla').after('<div id="space"></div>'); Documentation 回答2: try .insertAfter() here $(content).insertAfter('#bla'); 回答3: First of all, input element shouldn't have a closing

.append(), prepend(), .after() and .before()

懵懂的女人 提交于 2019-11-26 08:39:05
问题 I am pretty proficient with coding, but now and then I come across code that seems to do basically the same thing. My main question here is, why would you use .append() rather then .after() or vice verses? I have been looking and cannot seem to find a clear definition of the differences between the two and when to use them and when not to. What are the benefits of one over the other and also why would i use one rather then the other?? Can someone please explain this to me? var txt = $(\'#\' +