Web Development with jQuery®

(Elliott) #1

(^484) ❘ APPENDIX A EXERCISE ANSWERS
bapp01.indd 02/18/2015 Page 484



  1. Naming an instance of an event handler can be done by applying the event name, a dot, and
    then the namespace you want to use. You can apply multiple event names by repeating the
    same process.

  2. The off() method.

  3. Yes.

  4. You can use either click() with no arguments or trigger('click').

  5. A custom event handler begins with any event name not already in use in JavaScript; you can
    attach a custom event handler using that name using the on() method. The trigger() method
    can be used to fi re the custom event handler, as well as to send custom data to the event
    handler.


CHAPTER 4



  1. One possibility:


$('input').attr(
'value' : 'Some Value'.
'class' : 'someClass'
);

Another possibility:
$('input').addClass('someClass').val('Some Value');


  1. It might look like this:


$('a').attr('href', 'http://www.example.com');


  1. removeAttr()

  2. hasClass()

  3. No, HTML tags will not be present in the return value, only the element’s text content.

  4. Yes, HTML tags will be escaped and treated like text content.

  5. One bug that jQuery’s append() and prepend() methods work around in IE is how IE makes
    innerHTML Read Only on elements.
  6. One bug that jQuery’s append() and prepend() methods work around in Firefox is how
    Firefox occasionally loses form input values when appending or prepending HTML content
    using innerHTML.

  7. insertBefore()

  8. wrapAll()

  9. outerHTML


  10. http://www.it-ebooks.info