Elements toggleText() - KirkGarcia182/domExtend GitHub Wiki

toggleText()

Description

The element's innerHTML is switched between the two passed parameter texts.

Syntax

element.toggleText(text1 ,text2);

Parameters

text1 - A String representing the text that will be switched between text2. text2 - A String representing the text that will be switched between text1.

Return Value

The element you just manipulated so you can chain these methods.

Example

<!DOCTYPE html>
<html>
<head>
	<title>domExt Examples</title>
</head>
<body>
	<div id="app">
		<div class="menus">
			<ul id='menuList'>
				<li><a class='menuLink'>Menu 1</a></li>
				<li><a class='menuLink'>Menu 2</a></li>
				<li><a class='menuLink'>Menu 3</a></li>
			</ul>
		</div>
	</div>
	<script type="text/javascript" src="domExt.js"></script>
	<script type="text/javascript">
		window.$ = document;

		let app = $.byId('app');
		app.html('Hello World');

		app.toggleText('Hello World', 'Good Day');
		console.log(app);
		/* Result
			<div id="app">
				Good Day
			</div>
		*/

		app.toggleText('Hello World', 'Good Day');
		console.log(app);
		/* Result
			<div id="app">
				Hello World
			</div>
		*/
	</script>
</body>
</html>
⚠️ **GitHub.com Fallback** ⚠️