The _contents
variable contains a String representation of whatever was placed between the widget’s open and close tags.
eg. if you call your widget like so <<toc 2>>It works!<</toc>>
then the _contents
variable will contain a String value of “It works!”.
Based on the examples you’ve supplied I think you are misunderstanding how jQuery selectors work, specifically when used with the $(selector)
and find(selector)
functions.
A selector is meant define the HTML element(s) you want the function to find, using a query made up of a combination of element-type and/or element-id and/or element-class and/or element-attributes. These selectors look very similar to the ones used when applying CSS to the contents of a page.
eg. if you have a HTML structure like the following within your page…
<div id="images">
<img src="url-to-image1">
<img src="url-to-image2">
<img src="url-to-image3">
</div>
…then one of the possible selectors you could use to find all three of the <img>
elements within that structure is…
$('#images').find('img')
…which works by first searching the page’s Document Object Model for an element that has an ID attribute equal to “images”, and then searching the child/descendent elements of it to find any elements that have a type of img.
It should be noted that you need to use a contains selector if you want to search the Textual content of a page for specific Text.
eg. If your Passage contained the following content…
<p>A quick brown fox jumps over the lazy dog.</p>
…and you wanted to find the <p>
element that contain the text brown fox then one of the selectors you could to do that is…
$("p:contains('brown fox')")
but the result returned by the above function would contain a reference to the <p>
element the text was found in, not a reference to the text itself.
So in your example you are searching the HTML element’s of the “passage” area of the page looking for It works! …
$(ev.content).find(`It works!`).hide();
$(`It works!`).show();
…and even if we ignore the fact you have a exclamation character in that selector that query won’t return a result because the DOM doesn’t contain any <it>
or <works>
element-types in it.
note: One simple way to test your jQuery selectors is to open the Console of your web-browser while viewing the relevant Passage of your Story HTML file. And then executing the jQuery function call there to see what it returns.
eg. If I viewed the Passage that contained the <div>
plus <img>
element structure I mentioned earlier and then executed the related selector example within the Console it would of returned an Array containing three <img>
elements.