javascript - Copy an attribute from one element to another with jQuery -


I have the following jQuery code that does not appear to be anything when the link is clicked, then I Url attribute is trying to copy the value of iframe to the src attribute.

Actually it is considered to open links in an iframe (instead a new link is clicked if the content of the iframe is changed) rather than acting like normal link.

What's wrong with my code?

  $ ('p.tweet a'). Click (function () {var link = $ (this) .attr ('url'); $ ('ARTR' ('src', link);})    < P> 

What's wrong with my code?

You can subscribe to an anchor's click handler Do not cancel the default action by returning false and thus will not leave a chance for your script to execute the browser before redirecting it away from the page:

  $ ('p .tweet a '). Click (F $ ('Href'); $ ('iframe'). Attr ('src', link); return false;});   < P> And by the way by the notice I have used  $ (this) .attr instead of 'code' $ (this) .attr ('href')  ('url') .  href  attribute is more common for the anchor with the  url  attribute in the standard code, but if you have invented some markup in which an   url < / Code is> attribute, you can spin it.   

Comments