Search code examples
javascriptjqueryoptimizationsyntaxchaining

jQuery chaining to create concatenated string


Pretty simple, but I'm doing something wrong. I want to do a nice clean chain here, rather than declaring a var and then concatenating it:

the_function( null, null, 
   $( this ) // START string I'm passing as a parameter
   .attr( 'data-href' )
   .html( '|foo:' + event.var ) 
); // END string I'm passing as a parameter

I realize that .html() is invalid here, what is correct?


Solution

  • Huh? do you mean to do something like this

    the_function( null, null, 
       $( this ) // START string I'm passing as a parameter
       .attr( 'data-href' ) +  '|foo:' + event.var); 
    

    What you had

    $( this ).attr( 'data-href' ) // returns a string.. it doesn't have a html method