Skip to content

Instantly share code, notes, and snippets.

@jerlyrosa
Last active September 6, 2020 00:02
Show Gist options
  • Save jerlyrosa/0cba3f57ee3ad5030e4fafc4696eb4c9 to your computer and use it in GitHub Desktop.
Save jerlyrosa/0cba3f57ee3ad5030e4fafc4696eb4c9 to your computer and use it in GitHub Desktop.
Acceder a un elemnto por su ID con el DOM en javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p id='text-1'>Lorem ipsum dolor sit amet consectetur adipisicing elit. Harum accusamus est eveniet ad,
quibusdam sapiente nesciunt cum adipisci possimus doloribus a maxime vitae alias sequi
ipsum labore enim distinctio quaerat?</p>
<p id='text-2'>Lorem ipsum dolor sit amet consectetur adipisicing elit. Harum accusamus est eveniet ad,
quibusdam sapiente nesciunt cum adipisci possimus doloribus a maxime vitae alias sequi
ipsum labore enim distinctio quaerat?</p>
<script>
var element = document.getElementById('text-1');// Acceder un elemeto con el ID
console.log(element)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment