How to get and set HTML element value by class name with jQuery

1 Answer

0 votes
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>

<p class="pc">Text text text</p>

<p class="p_new"></p>

<script>
$(document).ready(function() {
  var pp = $(".pc"); // get
  $(".p_new").text("p_new: " + pp[0].innerHTML); // set
});
</script>

</body>
</html>

<!--
run:

Text text text

p_new: Text text text

-->

 



answered Jan 10, 2019 by avibootz
...