$(..." />
The init code should go into the .ready(), not your library functions, those can be defined in a seperate . Js file script src="yourFunctions. Js"> $(document).
Ready(function(){ $('a. ReviewLink'). Click(function() { displayData(parameters go here....); // in yourFunctions.
Js }); }); My name isAttr('data-lastname')); }) Note: You HAVE to use either jQuery's attr() or native getAttribute() method to retreive 'data-' values I use 'data-' myself all the time.
The init code should go into the .ready(), not your library functions, those can be defined in a seperate . Js file. An alternative to passing inline parameters without using inline javascript, is to use HTML5's 'data-' attribute on tags.
You can use it in xhtml, html etc as well and it just works. Html: My name is jquery: $('div'). Click(function(){ alert($(this).
Attr('data-name') + ' ' + $(this). Attr('data-lastname')); }); Note: You HAVE to use either jQuery's .attr() or native .getAttribute() method to retreive 'data-' values. I use 'data-' myself all the time.
Thanks. The only thing I'm not clear on is how I get the parameters. The HTML was dynamcially generated originally and that's why I used the onclick="displayData(params);" attribute, as I defined the param values into each link at runtime.
I can see how the example above works, but I just can't see where the parameters to pass to displayData are coming from when I click on the link. Sorry to be thick! :-) – Cydaps Sep 2 '10 at 21:41 see addendum ;) – BGerrissen Sep 2 '10 at 21:47 That's pretty cool!
I guess it needs a different DocType... I'll have a search online for which one to use for HTML5, this sounds perfect! :-) – Cydaps Sep 2 '10 at 21:50 Nah, you don't need a different doctype, only when html validation is important and even then chances are a lot of your html is invalid but actually valid... – BGerrissen Sep 2 '10 at 22:01 Shifting the code around worked really well, and i've gone for the HTML5 data attributes. DocType seems to work for all browsers I've tested.It's even working with the old onclick="" attribute I had before!
Thanks! – Cydaps Sep 2 '10 at 22:21.
As pointed out by Skilldrick, displayData doesn't need to be defined inside your document ready wrapper (and probably shouldn't be). You are correct in wanting to use the jQuery click event assignment rather than onClick - it makes your code easier to read, and is required by the principle of Unobtrusive Javascript. As for those parameters that you want to pass, there are a few ways to go about the task.
If you are not concerned with XHTML compliance, you could simply put some custom attributes on your link and then access them from your script. For example: View Details And then in your click event: $('a. ReviewLink').
Click(function() { var booktitle = $(this). Attr('booktitle'); var isbn = $(this). Attr('isbn'); var pubdate = $(this).
Attr('pubdate'); var price = $(this). Attr('price'); displayData(booktitle, isbn, pubdate, price); }); I'm sure someone on here will decry that method as the darkest evil, but it has worked well for me in the past. Alternatively, you could follow each link with a hidden set of data, like so: View Details Book Title ISBN Publish Date Price Create a CSS rule to hide the data list: .
Book-data { display: none; }, and then in your click event: $('a. ReviewLink'). Click(function() { var $bookData = $(this).
Next('. Book-data'); var booktitle = $bookData. Children('.
Book-title').text(); var isbn = $bookData. Children('. Book-isbn').text(); var pubdate = $bookData.
Children('. Book-pubdate').text(); var price = $bookData. Children('.
Book-price').text(); displayData(booktitle, isbn, pubdate, price); }); There are lots of ways to accomplish your task, but those are the two that spring most quickly to mind.
Thanks man, these are also useful ideas! I guess the HTML5 "data" attribute tags superseeds this, but really useful as an alternative. :-) – Cydaps Sep 2 '10 at 21:54 Yeah, those data attribute tags definitely solve the problem cleanly.
The only issue with using them would be if you need to support older browsers that don't support HTML5. Then again, if you're supporting an older browser, XHTML compliance is probably a concern, so the normal custom attributes still wouldn't work... – Ender Sep 2 '10 at 22:10 @Ender: Yes, they do, even in IE6, see Do HTML5 custom data attributes “work†in IE 6? – Marcel Korpel Sep 2 '10 at 22:46 @Marcel - Sorry, I was unclear there.
I didn't mean that it would break, just that custom attributes aren't XHTML compliant, using standard W3C validators. Of course you could always define your own doctype, but that's a headache in itself. – Ender Sep 2 '10 at 23:16 1 Again, the answer to that problem is simply ; your headaches will vanish instantly, and much cheaper than paracetamol.
– Marcel Korpel Sep 2 '10 at 23:23.
I worked this up, so even though the question is answered, someone else might find it helpful. jsbin.com/axidu3 HTML View Reviews Book Title 2 516AHGN1515 1999-05-08 $25.00 Book Title 2 JavaScript CSS.
This is definitely a neat solution if not using the HTML5 data attributes. Thanks for such a clean example Sandro. – Cydaps Sep 3 '10 at 7:38.
This method must use a user-initiated action, such as clicking on a link or tabbing to a link and pressing enter, to open a pop-up window. The Pop-up Blocker feature in Microsoft Internet Explorer 6 blocks windows that are opened without being initiated by the user. Microsoft Internet Explorer 5 and later allows further control over modal dialog boxes through the status and resizable values in the varOptions parameter of the showModalDialog method.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.