I am trying to see if possible if there is a way with jquery to create dynamic buttons. The buttons will be exactly the same but pass specific variables to functions that link to sites or create links to sites. I dont want to have to create each new list item if I have over 300 of them. Is there some way to create a function for each list item to create the buttons dynamically?
Here is the html
<nav id="menu">
<div id="app">
<ul class="List"><li><span>Enter Number below</span>
</li>
<div id="number">
<input type="text" name="number" id="textbox1" value="22984">
</div>
<li><span>Disney</span>
<ul id="programs">
<li><span>Lands</span>
<ul id="10min">
<li><span>Adventureland</span>
<ul id="Adventureland">
<li class="Label"> </li>
<button class="redirect" id="AdventureLand">Open Website</button><br/>
<button class="txtLinky" id="Adventureland">Click Link</button><br/>
<div id="linkified">value</div>
</ul>
</li>
<li><span>Frontierland</span>
<ul id="Frontierland">
<li class="Label"> </li>
<button class="redirect" id="Frontierland">Open Website</button><br/>
<button class="txtLinky" id="Frontierland">Click Link</button><br/>
<div id="linkified">value</div>
</ul>
</li>
<li><span>Fantasyland</span>
<ul id="Fantasyland">
<li class="Label"> </li>
<button class="redirect" id="FantasyLand">Open Website</button><br/>
<button class="txtLinky" id="Fantasyland">Click Link</button><br/>
<div id="linkified">value</div>
</ul>
</li>
<li><span>Tomorrowland</span>
<ul id="Tomorrowland">
<li class="Label"> </li>
<button class="redirect" id="TomorrowLand">Open Website</button><br/>
<button class="txtLinky" id="Tomorrowland">Click Link</button><br/>
<div id="linkified">value</div>
</ul>
</li>
</ul>
</li>
</li>
</ul>
</li>
</ul>
Here is the javascript
$(".redirect").click(function(){
goUrl = 'http://www.example.com/' + $(this).attr('id') + '?referringRepId=' + $("#textbox1").val();
window.location = goUrl;
});
$(".txtLinky").on("click", function () {
var link = 'Copy and paste '+ 'http://teambeachbody.com/shop/-/shopping/' + $(this).attr('id') + '?referringRepId=' + $("#textbox1").val();
$(this).parent().children('#linkified').html(link);
$(this).parent().children('#linkified').linkify({
tagName: 'a',
target: '_blank',
newLine: '\n'
});
$(this).parent().children('#linkified');
});
here is jsfiddle http://jsfiddle.net/VFhK9/18/
ulcontainingdivs andlis? Just saying...