Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Pass it a closure that will handle it when you're done.</p> <pre><code>function replacer(match) { if (isYoutubeLink()) { getYoutubeEmbedCode(function(){//code to change URLs here}); } // repeat for other types of urls } </code></pre> <p>I would not structure my code exactly like this, I would abstract that closure to a variable that is visible to the scope of the call but this is for succinctness.</p> <p>--Edit--</p> <p>After more though I realize that this is not the approach you want to use at all. You're looking to replace the links (anchor tags) themselves, not the href attributes on them.</p> <p>1) Select all of the anchor tags you expect to change into youtube videos and store them in an array. This is easy if you give them all a class or data-attribute (I prefer data-attribute in this case since it makes comparison easier and less likely to collide with basic css classes).</p> <p>2) Loop through them, and compare their href values or their data-attribute names (&lt;--that's the advantage of using data-attribute) to decide which youtube vid to pull on a per-element basis. Pass the ajax call a callback function (a closure as I mentioned in my original post) that is passed the target anchor tag.</p> <p>3) Use the target anchor tag when the ajax comes back to place the youtube code after it (using append or something of the sort).</p> <p>4) remove the target anchor tag.</p> <p>5) now that you want to add something after the video, since you have the video here, you can do it now by targeting it.</p> <p>All done.</p> <p>This is a better approach in my opinion. Maybe I am missing the point of your post but from what I read it sounds to me like your approach is trying to do something other than what you really want to do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload