javascript - 'href' Not Showing Output on Click -
I am trying to expand a href link / display additional text when I click, but when I click I do, nothing happens.
When I run the html code, I can click on the link but it does not show text for some reason why any thoughts?
This code is:
& lt; Html & gt; & Lt; A href = "# 1" onclick = "$ ('divID'). Toggle ();" & Gt; Click to expand & lt; / A & gt; & Lt; Div id = "divid" style = "display: none;" & Gt; It has been expanded & lt; / Div & gt; & Lt; / Html & gt;
I try to keep the code as low as the code above will be repeated hundreds of times for each link.
Assume that you are using jQuery, you are misusing the CSS selector. Your line should be:
& lt; A href = "# 1" onclick = "$ ('# divID') Toggle ();" & Gt; Click to expand & lt; / A & gt; Any element with #
in #divID
id
of divID
Code>, while divID
tags (such as
using divID
) and < / Code>)
will search) And, for you to understand why your previous code does not work.
You can also add CSS selectors to reduce your selection in the future, although this is not necessary with the ID selector:
And if you completely use Do not :
& lt; A href = "# 1" onclick = "If (document.getElementById ('divId') style.display == 'none') document.getElementById ('divId'). Style.display = 'block'; else document .getElementById ('divId'). Style = 'none'; & Gt; Click to expand & lt; / a & gt;
or divide it into its own work:
& lt ; Script> function toggle elementBiID {ID (if document.getElementById (id) .style.display == 'none') {document.getElementById (id) .style.display = 'block';} and { Document.getElementById (id) .style.display = 'none';}} & lt; / script> & lt; a href = "# 1" onclick = "toggleElementById ('divId');" & gt; Extension Click to & lt; / a & gt;
Comments
Post a Comment