0

I am using coda style jquery plugin to show balloon tooltip. Here is link :http://www.uhleeka.com/blog/2009/11/bubbletip/

I have written this jquery to display ballon tooltip on click of element.

This what i am doing this on id's but how can i do this using class name. How can i do insted of writting bubbletip function for each id's how can i write single(common) jquery function to apply bubbletip.

<script type="text/javascript">
    $(document).ready(function() {
            $('#fee').bubbletip($('#tip1_focusblur'), {
                deltaDirection: 'right',
                bindShow: 'click',
                bindHide: 'blur'
            });



            $('#price').bubbletip($('#tip2_focusblur'), {
                deltaDirection: 'right',
                bindShow: 'click',
                bindHide: 'blur'
            });

    });
</script>

<p>Input box 1<input type="text" id="fee" value="focus me!" /></p>

<div id="tip1_focusblur" style="display:none; max-width:330px;">
    <pre class="tip">
        This is the div where help can be display.
    </pre>  
</div>

<p>Input box 2<input type="text" id="price" value="focus me!" /></p>

<div id="tip2_focusblur" style="display:none; max-width:330px;">
    <pre class="tip">
        This is the div where help can be display.
    </pre>  
</div>

Edit: I have found soloution: As per JofryHS suggest , i have tried this solution.

Is this good solution ??

Javascript:

$(document).ready(function() {
    var count = 0;
        $('[data-bubble]').each(function() {    
            count++;
            var data = $(this).attr('data-bubble');
            $(this).parent().append($('<div class="bubble" id="bubble_'+ count+ '">' + data + '</div>'));
            $(this).bubbletip('#bubble_'+count, {
                deltaDirection: 'right',
                bindShow: 'click',
                bindHide: 'blur'
            });
        });
});

HTML:

<input type="text"  data-bubble="This is Test text 1"  value="focus me!" />

<input type="text"  data-bubble="This is Test text 2"  value="focus me!" />
Kango
  • 809
  • 11
  • 27
  • 48

2 Answers2

0

one way is to create a global function and call it every time you need it

 function bubbleTip(obj1,obj2){
    $('#'+obj1).bubbletip($('#'+obj2), {
            deltaDirection: 'right',
            bindShow: 'click',
            bindHide: 'blur'
        });
}

and call the function with an arguments where you want to show the tooltip.

$(function(){ //shorthand for document.ready
   bubbleTip('fee','tip1_focusblur');
   bubbleTip('price','tip2_focusblur');
});
BenMorel
  • 34,448
  • 50
  • 182
  • 322
bipen
  • 36,319
  • 9
  • 49
  • 62
0

You can use the HTML data- attribute to automatically call the bubbletip.

HTML + Script (UNTESTED):

<script type="text/javascript">
    $(document).ready(function() {
            $('[data-bubble!=""]').each(function() {
                var target = $(this).data('bubble');
                $(this).bubbletip($('#' + target), {
                    deltaDirection: 'right',
                    bindShow: 'click',
                    bindHide: 'blur'
                })
            });
    });
</script>

<p>Input box 1<input type="text" id="fee" data-bubble="tip1_focusblur" value="focus me!" /></p>

<div id="tip1_focusblur" style="display:none; max-width:330px;">
    <pre class="tip">
        This is the div where help can be display.
    </pre>  
</div>

<p>Input box 2<input type="text" id="price" data-bubble="tip2_focusblur" value="focus me!" /></p>

<div id="tip2_focusblur" style="display:none; max-width:330px;">
    <pre class="tip">
        This is the div where help can be display.
    </pre>  
</div>

As long as you include the script snippet above, anywhere in your HTML tag you can put data-bubble with the target and it should automatically be bound to your bubbletip.

Similar question: Jquery select all elements that have $jquery.data()

jQuery data

Community
  • 1
  • 1
JofryHS
  • 5,804
  • 2
  • 32
  • 39