Ok so I wanna ask a simple jQuery question about arrays of objects.
If I get all elements (for example all paragraphs) from an html page and store them in an array how can I access one of them to do stuff with it?
For example let's say I have this html:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<p>Paragraph 3</p>
<button id="myButton">Click here</button>
<script src="jquery-1.6.2.min.js"></script>
<script src="script.js"></script>
</body>
</html>
This is my script.js:
$(document).ready(function(){
$("#myButton").click(function(){
var $paragraphs = $("p");
$paragraphs.detach(); //Works fine, removes all elements
//$paragraphs[0].detach(); //Doesn't work!
});
});
I'm trying to call detach on the first element of the array, so that I can remove the first paragraph but it doesn't seem to work...
Is there any way to access the first paragraph without using id attributes?