Adding simple div and span tag to two specific Javascript/PHP strings -


i can't seem working or find solution that's directly applicable problem online.

i need add div (to change background) , span (to add icon) of specific $str in javascript/php. tried multiple angles i'm deifnitely doing wrong because can't div attach 1 specific $str.

here code i'm using:

function fav_link( $return = 0, $action = "", $show_span = 1, $args = array() ) { global $post; $post_id = $post->id; extract($args); $str = ""; if ($show_span)     $str = "<span class='fav-span'>"; if ($action == "remove"):     $str .= fav_link_html($post_id, __('remove favorite','framework'), "remove"); elseif ($action == "add"):     $str .= fav_link_html($post_id, __('add favorites','framework'), "add"); elseif (fav_check_favorited($post_id)):     $str .= fav_link_html($post_id, __('remove favorite','framework'), "remove"); else:     $str .= fav_link_html($post_id, __('add favorites','framework'), "add"); endif; if ($show_span)     $str .= "</span>"; if ($return) { return $str; } else { echo $str; } } 

as can see above, span class there works fine. applies 4 options. want apply div , span 2 "remove favorite" strings , not have them affect "add favorites" strings. also, existing span in code isn't of use me.

here php displays above code:

<?php if(get_field('enable_favorites_system','option') && is_user_logged_in()) {             fav_link();             } else if(get_field('enable_favorites_system','option') && !is_user_logged_in()) {             echo '<span class="fav-span"><a href="#" class="slinks" id="fav-nonlogged"><i class="icon-star"></i>'.__('add favorites','framework').'</a></span>';} ?></li> 

output html when not favorited (source:inspect element):

<span class="fav-span"><a class="slinks fav-link" href="?favaction=add&amp;postid=4729" title="add favorites" rel="nofollow"> add favorites</a></span> 

output html when favorited (source:inspect element):

<span class="fav-span"><a class="slinks fav-link" href="?favaction=remove&amp;postid=4729" title="remove favorite" rel="nofollow"> remove favorite</a></span> 

new edit - code fav_link_html

function fav_link_html($post_id, $opt, $action) { $link = "<a class='button small sl-bd fav-link' href='? favaction=".$action."&amp;postid=". $post_id . "' title='". $opt ."' rel='nofollow'><i class='icon-bookmark'></i> ". $opt ."</a>"; $link = apply_filters( 'tdp_fav_link_html', $link ); return $link; } 

new edit - desired html

so way link says "add favorites" , when clicked, says "remove favorite". system works fine. hope add blue background , icon when in "remove favorite" state. give user clear indication has been set favourite of theirs.

hope adds clarity!

if can me this, i'd grateful. thank much!


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -