Questions tagged [jquery-chaining]

Chaining allows us to run multiple jQuery methods (on the same element) within a single statement.

With jQuery, you can chain together actions/methods.

Chaining allows us to run multiple jQuery methods (on the same element) within a single statement. This way, browsers do not have to find the same element(s) more than once. To chain an action, you simply append the action to the previous action.

Example

<div>Hello</div>
$("div")
  .addClass("chain")
  .css("color", "red")
  .text("Hello world")

Result

<div class="chain" style="color: red">Hello world</div>
40 questions
98
votes
3 answers

When should I use jQuery deferred's "then" method and when should I use the "pipe" method?

jQuery's Deferred has two functions which can be used to implement asynchronous chaining of functions: then() deferred.then( doneCallbacks, failCallbacks ) Returns: Deferred doneCallbacks A function, or array of functions, called when the Deferred…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
13
votes
2 answers

Chain of Jquery Promises

I have a simple chain of events: Get Columns from a metaData table (async) load selected columns (async) render list I used to just the chain these functions, each calling the next when it had completed. However, its not very obvious what's…
Jon Wells
  • 4,191
  • 9
  • 40
  • 69
6
votes
2 answers

Write a jQuery Plugin that return values

I'm writing a jQuery plugin that stores some data in some cases. I'd like to write it in a very flexible way, where I'll can change an input parameter to obtain some value that were stored by the plugin. Explanation: When I call…
Erick Petrucelli
  • 14,386
  • 8
  • 64
  • 84
3
votes
2 answers

How to create elements and select them on the fly with jQuery

I'm a bit stumped with this. I would like to create some elements (using jQuery), call a function on that wrapped set, and continue this process several times via a chain. For example, $('
') .call_plugin() .append('
maximus
  • 2,417
  • 5
  • 40
  • 56
3
votes
3 answers

adding 'if' logic to a jQuery chain

Let's say I have the following jQuery: // pseudocode : $(this) .doSomething .doSomething .selectSomething .doSomething .animate({ opacity: 1 }, 150) .end() .selectSomethingElse …
DA.
  • 39,848
  • 49
  • 150
  • 213
3
votes
1 answer

jQuery Plugin: Using callback to alter plugin behavior

I am using the jQuery token input plugin and would like change its behavior when a token is added. I added an "onAddToken" callback to the original code so I can see when a token is added to the input box, but I'm not sure how to alter…
Matt Norris
  • 8,596
  • 14
  • 59
  • 90
3
votes
1 answer

jQuery adding / chaining elements to one variable

how can I turn this into something faster: $.each(data, function(key, val) { rcItemsLi.eq(index++).append(''); }); rcItemsContent =…
Ron
  • 3,975
  • 17
  • 80
  • 130
2
votes
3 answers

Reference to current object in Jquery chain

The following chain works: $("

").html('message').hide().appendTo("#chat").fadeIn() .parent().scrollTop($('#chat')[0].scrollHeight); But this doesn't: …
tiktak
  • 1,801
  • 2
  • 26
  • 46
2
votes
1 answer

Chaining find() to val()

Is there a way to chain find() following val()? For example, given the following code, I would like to clear the values of all the inputs but only toggle the required property of the inputs that have a class of .required: $('#some-selector') …
dtburgess
  • 613
  • 5
  • 19
2
votes
1 answer

Multiple chained .on('click') event listeners in jQuery

I have several click handlers on a carousel plugin (GitHub repo here). When I initially coded it, I forgot about jQuery chaining: $gallop.on("click", ".advance", function(){ [snip 1] }) $gallop.on("click", ".retreat", function(){ [snip 2]…
brentonstrine
  • 21,694
  • 25
  • 74
  • 120
2
votes
1 answer

Add method to chaining in jQuery plugin

I am trying to write an auto complete jQuery plugin. The desired usage: $('.advancedSelect').advancedSelect({/*plugin options*/}).change(function(){})/*.otherJQueryMethods*/; The implementation: $.fn.advancedSelect = function({ return…
Nick
  • 95
  • 8
2
votes
2 answers

Jquery Contains and Not Contains Chaining

Image i have table like this : …
Gates
  • 23
  • 1
  • 4
2
votes
1 answer

How should double quotes be escaped in coffeescript regular expressions?

I have the following line of coffeescript code (both dCnt and sDesc are jQuery objects), which does some basic cleaning up of a block of HTML while moving its location: dCnt.append(sDesc.html().replace( /
/gi, '

'…
2
votes
1 answer

Does .prependTo() follow the jQuery chaining?

I'm making a project, and in some line, there's a check button that when checked it relocates it's parent to the bottom. Here's it's markup :
Rafael Adel
  • 7,673
  • 25
  • 77
  • 118
1
vote
2 answers

Execute a set of work in a loop only after the previous set has completed

I have some code that completes a distinct set of operations in a chain. The set of operations, itself, is executed in a loop. Because of the nature of the system I'm dealing with, the operation sets need to be executed synchronously (i.e., the next…
Joey Aron
  • 11
  • 1
1
2 3
Adresse IP 10.2.3.4
Zobi blabla
Adresse