Skip to Content
Learning jQuery - Fourth Edition
book

Learning jQuery - Fourth Edition

by Jonathan Chaffer, Karl Swedberg
June 2013
Beginner content levelBeginner
444 pages
9h 45m
English
Packt Publishing
Content preview from Learning jQuery - Fourth Edition

Content getter and setter methods

It would be nice to be able to modify the pull quote a bit by dropping some words and replacing them with ellipses to keep the content brief. To demonstrate this, we have wrapped a few words of the example text in a <span class="drop"> tag.

The easiest way to accomplish this replacement is to directly specify the new HTML entity that is to replace the old one. The .html() method is perfect for our needs:

$(document).ready(function() {
  $('span.pull-quote').each(function(index) {
    var $parentParagraph = $(this).parent('p');
    $parentParagraph.css('position', 'relative');

    var $clonedCopy = $(this).clone();
    $clonedCopy
      .addClass('pulled')
      .find('span.drop')
        .html('&hellip;')
      .end() .prependTo($parentParagraph); }); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning jQuery 3 - Fifth Edition

Learning jQuery 3 - Fifth Edition

Adam Boduch, Jonathan Chaffer, Karl Swedberg
jQuery Cookbook

jQuery Cookbook

Cody Lindley

Publisher Resources

ISBN: 9781782163145Other