0

Is it possible to run two(2) funcions with the same id?

<a href="#icon" class='icon' id='icon' >

Edited by Dani: Formatting fixed

3
Contributors
8
Replies
29
Views
2 Years
Discussion Span
Last Post by SimonIoa
0

OK so i got a unique id and two classes
<a href="#icon" class='icon icon_button' id='icon<?php echo $id; ?>' >

This is the first fuction i want to run

$('body').on("click",'.icon_button',function()
{

    var KEY = parseInt($(this).attr("data"));
    var ID = $(this).attr("id");
    if(KEY=='1')
    {
        var sid=ID.split("icons");
    }
    else
    {
        var sid=ID.split("icon");
    }
    var New_ID=sid[1];
    var REL = $(this).attr("rel");
    var URL=$.base_url+'some.php';
    var dataString = 'id=' + New_ID +'&rel='+ REL;
    $.ajax
    ({
        type: "POST",
        url: URL,
        data: dataString,
        cache: false,
        success: function(html)
        {
            if(html)
            {

            }
        }
    });
    return false;
});

});

and the second one is a colorbox window

$(document).ready(function(){
    //Examples of how to assign the ColorBox event to elements

    $(".icon").colorbox({width:"50%", height:'70%', inline:true});
    //Example of preserving a JavaScript event for inline calls.
    $("#click").click(function(){ 
        $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
        return false;
    });


});

now it should do the first function i wanted it to do and open a colorbox window

<div style="display:none">
                            <div id="icon" style="margin-left:20px">
                            <span class="show-pop-up">You believe This</span><span ><a id="pop-up" href="<?php echo $base_url?>pictures.php"><?php echo $lang['ViewAll'].'('.$lang['photo'].')' ?></a></span><br /><br><br>

                            </div>
                        </div>
0

Don't place '#' in front of your name in HTML id property. The '#' is there to reference the id prop in CSS and libs like jQuery.

So what exactly is your question?

0

My mistake. :)

Regardless, what exactly is it you want to do? I couldn't quite work out from your explanation.

0
OK my bad. I want to make a button so when clicked the user likes a certain post and it will open a colorbox window (i use colorbox in many occassions, so it works).m So it has to go from Like to Unlike and fromm Unline to Like and open a colorbox window. I made the scripts to work both for colorbox and Like/Unlike button and i can't make them to work at the same time. It will Like/Unlike or open a Colorbox BUT not both. I hope i was understandable
0

Where is this 'data' attribute?

var KEY = parseInt($(this).attr("data"));

I can't see it in:

<a href="#icon" class='icon icon_button' id='icon<?php echo $id; ?>' >

Actually, I can't see 'rel' either. Are you sure the HTML you posted is being used with these scripts?

0
<a href='#like' class='like like_button' id='like<?php echo $omsg_id;?>' title='<?php echo $like_status;?>' rel='<?php echo $like_status;?>' data='<?php echo $shareKey ?>'><?php echo $like_status;?></a>

this is the js script

*Like and Unlike*/
$('body').on("click",'.like_button',function()
{

var KEY = parseInt($(this).attr("data"));
var ID = $(this).attr("id");
if(KEY=='1')
{
var sid=ID.split("likes");
}
else
{
var sid=ID.split("like");
}


var New_ID=sid[1];
var REL = $(this).attr("rel");
var URL=$.base_url+'message_like_ajax.php';
var dataString = 'msg_id=' + New_ID +'&rel='+ REL;
$.ajax({
type: "POST",
url: URL,
data: dataString,
cache: false,
success: function(html){
if(html)
{
if(REL=='Like')
{
$("#elikes"+New_ID).show('slow').prepend("<span id='you"+New_ID+"'><a href='#'>You</a> like this.</span>");
$("#likes"+New_ID).prepend("<span id='you"+New_ID+"'><a href='#'>You</a>, </span>");
$('#'+ID).html('Unlike').attr('rel', 'Unlike').attr('title', 'Unlike');
}
else
{
$("#elikes"+New_ID).hide('slow');
$("#you"+New_ID).remove();
$('#'+ID).attr('rel', 'Like').attr('title', 'Like').html('Like');
}
}

}
});

return false;
});

and this is the colorbox script

<script type="text/javascript">

$(document).ready(function(){
    $(".like").colorbox({width:"50%", height:'70%', inline:true});
    //Example of preserving a JavaScript event for inline calls.
    $("#click").click(function(){ 
        $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
        return false;
    });


});
</script>

<div style="display:none">
                            <div id="like" style="margin-left:20px">
                            <span class="show-pop-up">You believe This</span><span ><a id="pop-up" href="<?php echo $base_url?>pictures.php"><?php echo $lang['ViewAll'].'('.$lang['photo'].')' ?></a></span><br /><br><br>

                            </div>
                        </div>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.