How to use CSS to change the background color of a paragraph after clicking a link in an HTML page
P粉311423594
2023-09-02 00:38:08
<p>Can I change the background color of a paragraph when I click a link on the page. </p>
<blockquote>
<pre class="brush:php;toolbar:false;"><a href="#p4">Jump to P4</a>
<p id="p4">I am P4</p></pre>
</blockquote>
<p>What do I need to write in CSS to achieve this -</p>
<blockquote>
<p>p {Background color: yellow; }</p>
</blockquote></p>
You cannot change the properties of an element by clicking on another element, but you can do so through JavaScript. Just add the
<script>
tag at the end of your<body>
tag andonclick on the
<a>tag ()
event: