Link to home
Start Free TrialLog in
Avatar of wilson1000
wilson1000

asked on

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

Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

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

Here are all selectors
http://api.jquery.com/category/selectors/

can you post the code where it appears?
My test data

<html>
    <head>
      <title></title>
      <script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>  
    </head>
    <body>
    <a/>
    <a></a>
    <div id="test"></div>
  <script>
  $("<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")
  </script>
    </body>
  </html>

Open in new window

@mplungian

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.
Avatar of wilson1000
wilson1000

ASKER

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.

http://www.pc-site.co.uk/dell/#pag

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() {
				func_tool(tool,tableid,(currpage-1));
				return false;
			})).appendTo("#pagination").wrap("<span class=\"prev\"></span>");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you
Yes I thought the same about the live()