Skip to content

Instantly share code, notes, and snippets.

@mbuttler
Last active August 29, 2015 14:23
Show Gist options
  • Save mbuttler/b45dd4a736a4aadc6fac to your computer and use it in GitHub Desktop.
Save mbuttler/b45dd4a736a4aadc6fac to your computer and use it in GitHub Desktop.
Matt's jQuery question 6/16
// So here's my jQuery script.
$(document).ready(function(){
$("#one").after("<p>Awesome funtimes for all!</p>");
$("#two").after($("p"));
$("p").remove();
});
//how does it know that by "p" I mean my paragraph? I don't declare it as a variable...
// but it still moves it after #two and removes it... why is that?
<!DOCTYPE html>
<html>
<head>
<title>Result</title>
<script type='text/javascript' src='script.js'></script>
</head>
<body>
<div class="container">
<h2>Greetings</h2>
<div id="one">Div #1</div>
<div id="two">Div #2</div>
</div>
</body>
</html>
@dfmcphee
Copy link

In jQuery you can use any CSS selectors to select elements, including tag names. When you use $("p") it is selecting all p tags on the page.

https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment