[jQuery] [beginner] passing variables to a Jquery function
Hi all,<div>I couldn't find a good answer to this, although it has probably been answered before, apologies!</div><div>
</div><div>I have a link</div><div><a id="doit" href="/bla/something.php?id=123&type=456">do it</a></div>
<div>
</div><div>And some jQuery code</div><div>
</div><div><div>$("#doit").click(function(){ // upon click</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>$.get(this.href); // call the URL</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>$('#doit').replaceWith("I've been there (<a href=/bla/something.undo.php?id=123&type=456'>undo</a>)");</div><div>
<span class="Apple-tab-span" style="white-space:pre"> </span>return false;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> });</div><div>
</div><div>My problem is that I want to populate the URL that's in "replaceWith" with the correct id, depending on the id that was in the original link. I've thought of using a fake attribute in the link somehow (<a type="456" id="doit"), but I can't seem to get it to work, and I'm not sure this is the right approach...</div>
<div>
</div><div>What would be the jquery-like best way to do this?</div><div>
</div><div>Thanks!</div><div>Peter</div>
--
me: <a href="http://petervandijck.com">http://petervandijck.com</a>
blog: <a href="http://poorbuthappy.com/ease/">http://poorbuthappy.com/ease/</a>
global UX consulting: <a href="http://290s.com">http://290s.com</a>
free travel guides: <a href="http://poorbuthappy.com">http://poorbuthappy.com</a>
Belgium: (+32) 03/325 88 70
Skype id: peterkevandijck
</div>