user1071890
user1071890

Reputation: 17

adding a href class to javascript code?

Im using a jquery snippet to pull in a wordpress rss feed to my site. Im new to coding and pulled this together with some luck.

my question is how can I pass an href class="iframe" for code that looks like this?

rssoutput+="<li><a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a></li>"

thank you!

<script>
$(document).ready(function(){
        //Examples of how to assign the ColorBox event to elements
        $(".group1").colorbox({rel:'group1'});
        $(".group2").colorbox({rel:'group2', transition:"fade"});
        $(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
        $(".group4").colorbox({rel:'group4', slideshow:true});
        $(".ajax").colorbox();
        $(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344});
        $(".iframe").colorbox({iframe:true, width:"80%", height:"100%"});
        $(".inline").colorbox({inline:true, width:"50%"});
        $(".callbacks").colorbox({
            onOpen:function(){ alert('onOpen: colorbox is about to open'); },
            onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
            onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
            onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
            onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
        });

        //Example of preserving a JavaScript event for inline calls.
        $("#click").click(function(){ 
            $('#click').css({"background-color":"#fff", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
            return false;
        });
    });
</script>

Upvotes: 0

Views: 455

Answers (2)

Pastor Bones
Pastor Bones

Reputation: 7351

Just add the class attribute to the string

rssoutput+="<li><a href='" + thefeeds[i].link + "' class='iframe'>" + thefeeds[i].title + "</a></li>"

EDIT

where the ID of your iframe is myFrame

rssoutput += "<li><a href='" + thefeeds[i].link + "' class='iframe' target='myFrame'>" + thefeeds[i].title + "</a></li>"

Upvotes: 3

user1046334
user1046334

Reputation:

Learn to do the less "stringy" code (the code where everything is done with string manipulation), but to use structured objects. If you use jQuery, you can as well use jquery-mochikit-tags project from github.com (finding it left as an exercise to the reader :-) ) and create html programmatically and using jQuery constructs like append or appendTo like this:

$.LI(
  $.A(
    {'href': thefeeds[i].link, 'class': 'iframe'},
    thefeeds[i].title
  )
).appendTo('#containerOfRssOutput');

Upvotes: 0

Related Questions