Web Development with jQuery®

(Elliott) #1

Replacing Elements (^) ❘ 125
The following script demonstrates how jQuery’s replaceWith() and replaceAll() methods are used
to replace elements:
$(document).ready(
function()
{
$('input#mitchHedbergQuoteReveal1').click(
function(event)
{
event.preventDefault();
$(this).replaceWith(
"

\n" +
" I would imagine that if you could understand \n" +
" Morse code, a tap dancer would drive you crazy.\n" +
"

\n"
);
}
);
$('input#mitchHedbergQuoteReveal2').click(
function(event)
{
event.preventDefault();
$(this).replaceWith(
"

\n" +
" I’d like to get four people who do cart wheels
\n" +
" very good, and make a cart.\n" +
"

\n"
);
}
);
$('input#mitchHedbergQuoteReveal3').click(
function(event)
{
$('p#mitchHedbergQuote3').replaceAll(this);
}
);
$('input#mitchHedbergQuoteReveal4').click(
function(event)
{
$('p#mitchHedbergQuote4').replaceAll(this);
}
);
}
);
http://www.it-ebooks.info

Free download pdf