jQuery Short hand Tag?

Hi Experts,

I can't seem to find any information regarding the type of tag used in the following code snippet.

Would someone be kind enough to explain the syntax please?

Many thanks
$("<a/>").html("<span class=\"verdana\">&laquo; &nbsp;</span>Prev")

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
Insert a span in the innerHTML of an anchor that has no content already
Michel PlungjanIT ExpertCommented:
However it does not seem to work

Here are all selectors

can you post the code where it appears?
Michel PlungjanIT ExpertCommented:
My test data

      <script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>  
    <div id="test"></div>
  $("<a/>").html("<span class=\"verdana\">&laquo; &nbsp;</span>Prev")
  $("#test").html("<span class=\"verdana\">&laquo; &nbsp;</span>Prev")
  $("a").html("<span class=\"verdana\">&laquo; &nbsp;</span>Prev")

Open in new window

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!


If you pass a HTML string to jQuery function, $(), it just generates the DOM element(s), similar to JavaScript createElement(), but you can pass any HTML string with many elements in it.
You need to insert it in the DOM tree in order to see it, using one of jQuery methods like append(), prepend(), insertAfter() and so on.

And... html() does not insert, it replaces the innerHTML.
wilson1000Author Commented:
Hi, thanks for your post

This does work, I just wanted to understand the syntax a little better.

If you take a look at the following link you'll notice the pagination at the very top of the page. Click a digit or the next button and the "Prev" link appears.


I've added a little more of the script below to help shed some light but due to NDA I can't release the rest, apologies for that.

Thanks again

$("<a/>").html("<span class=\"verdana\">&laquo; &nbsp;</span>Prev").attr("href", "#").live( 'click',(function() {
				return false;
			})).appendTo("#pagination").wrap("<span class=\"prev\"></span>");

Open in new window

Michel PlungjanIT ExpertCommented:

it was the appendto we missed

$("<a/>").html("<span class=\"verdana\">&laquo; &nbsp;</span>Prev").appendTo('body')

That makes sense.

So jhp said it:

$("<a/>") // create a link
.html("<span class=\"verdana\">&laquo; &nbsp;</span>Prev") // replace the innerHTML
.attr("href", "#") // set the href to #
.live( 'click',(....) // attach/bind an event handler to all current and future links
.appendTo("#pagination") // append this link to the object with id="pagination"
.wrap("<span class=\"prev\"></span>") // wrap the link I guess

I would expect the wrap to come before the append

<div id="pagination" class="nicepagination center">
  <span class="prev">
    <a href="#" style="">
      <span class="verdana">« &nbsp;</span>Prev

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I think that that live() has no merit, but possible side effects.
Just regular .click(function () {... would suffice.
wilson1000Author Commented:
Thank you
Michel PlungjanIT ExpertCommented:
Yes I thought the same about the live()
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.