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
0
votes
1 answer

jQuery chaining css background-color, only works once

I'm trying to chain background-color changes of a paragraph with jQuery. The following code works on the first click: change color to green, hide it, show it, then change color to yellow. On the second click, the color changes to green, but nothing…
edj
  • 523
  • 7
  • 17
0
votes
1 answer

How to pass selected element to 'this' in the chained functions

I am trying to understand how chained function work and in particular how is it possible to pass the selected element to the chained functions. Assuming that we have a chained function as follow: var func = {}; func.remove= function() { …
cyrus-d
  • 749
  • 1
  • 12
  • 29
0
votes
2 answers

nice jquery load effect

I would like to load a page inside a div with fadeTo effects. I have created this function for that function show(div) { $("#showdata").fadeTo(300,0.0,function() { $("#showdata") .html('
NVG
  • 3,248
  • 10
  • 40
  • 60
0
votes
1 answer

Using Chained Promises with .when

I have 2 methods which return promises (shortened with non-async resolves) function methodA () { var d = $.Deferred(); d.resolve('A'); return d.promise(); } function methodB (dependency) { var d = $.Deferred(); // dependency…
raydenl
  • 397
  • 1
  • 4
  • 16
0
votes
2 answers

jQuery CSS chaining background image and z-index

I have a div where an image is generated.result. I need to set a background image within that div that will act as a layer on top of the generated image. I have the following, but can't get the image to show: image.appendTo($(".result")) $button…
Matt
  • 1,239
  • 4
  • 24
  • 53
0
votes
5 answers

jQuery .animate/.each chaining

I'm trying to combine matching something like: $(".item").each(function(i) { //animation here }); with jQuery's inherent chaining functionality that forces the animation to wait until the previous animation has completed,…
Aaron
  • 4,634
  • 1
  • 27
  • 43
0
votes
2 answers

How to access the one of the chained functions in a plugin?

How can I access the one of the chained functions in a plugin? this is my plugin, in which I need to return an appended element on the document. (function($){ $.fn.extend({ selection: function(options) { var…
Run
  • 54,938
  • 169
  • 450
  • 748
0
votes
1 answer

Separate pipe() and $.Deferred.resolve()

$.Deferred(function(dfr) { $("#container > div").each(function() { var $div = $(this); dfr = dfr.pipe(function() { return $div.fadeIn(); }); }); }).resolve(); Is there a way to load dfr separately in the…
Ajax3.14
  • 1,647
  • 5
  • 24
  • 42
0
votes
1 answer

Custom plugin using $.ajax call breaks chaining

I have created a jQuery plugin that is used to create html on a page with the xml that it reads from a webservice call. As a backup, if the webservice call fails, there is default xml stored in a var to use to build the html. Right now, the…
str8killinit
  • 167
  • 7
-2
votes
1 answer

How method chaining works in this case in JQuery

method chaining requires every method to return the jquery object but, when we use: $("div").click(function(){ //some code }).css("backgroundColor","blue"). how does the css method get executed without clicking the div? how does it know the jquery…
1 2
3