javascript - Binding Events rather than using onclick -


I have been better told to pair elements with work instead of onclick s. I agree with it because it is more than HTML, which is cleaner and easy to debug code.

But I'm having trouble doing this! I loop through some data with PHP (see below) and I'm currently using onclick to call a function. How can I share this onclick event on many elements that use jQuery?

  & lt ;? Php foreach ($ main_tags $ key = & gt; $ value) {? & Gt; & Lt; Li & gt; & Lt; An id = "& lt ;? php echo $ key ;? & gt;" Href = "#" onclic = "tag_shatch ('& lt; php echo $ key ;; & gt;'); return false;" & Gt; & Lt ;? Php echo $ key; ? & Gt; & Lt; Span class = "num-active" & gt; & Lt ;? Php $ value; ? & Gt; & Lt; / Span & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt ;? Php}? & Gt;  

Thanks for any help

  Lt; Ul id = "container" & gt; & Lt ;? Php foreach ($ main_tags $ key = & gt; $ value) {? & Gt; & Lt; Li & gt; & Lt; A href = "#" key = "& lt ;? php echo $ key ;;>" & Gt; & Lt ;? Php echo $ key; ? & Gt; & Lt; Span class = "num-active" & gt; & Lt ;? Php $ value; ? & Gt; & Lt; / Span & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt ;? Php}? & Gt; & Lt; / Div & gt; & Lt; Script & gt; $ (Function () {function tag_search () {}; $ ('# container a'). Click (function (e) {e.preventDefault (); tag_search.call (this, $ (this) .attr (' Key '));});}); & Lt; / Script & gt;  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -