Jimmy Geers
Jimmy Geers

Reputation: 742

jQuery select span class not working

Im trying to select the span by using the (.class) selector but for one or another reason this is not working.

<div class="text-wrap">
<div class="text-list">
  <div class="text-suggestion">
     <span class="text-label">Lorem</span>
  </div>
</div>
</div>

 jQuery(document).ready(function() {

        jQuery('.text-label').click(function(e){
            alert('lol');
        });
});

I can only select .text-wrapper the others are not working.. is this a jQuery program fault? I also have to say that im using the jQuery textext plugin.

UPDATE:

I forgot the quotes in my first post but this is not the problem. The code is also in a script tag otherwise it would not be possible to select the text-wrap div.

I still have the problem that everthing that is in the text suggestion div can't be triggered.

I am using the textext plugin from Textext

ANOTHER UPDATE afther the comment:

jQuery("#customfield_10000").keyup(function(e){
                            teller = teller + 1;
                            if(teller % 2 == 0){
                            if(e.keyCode == 13)
                            {
                                jQuery("#customfield_10001").focus();
                            }    

            crmAccount = jQuery(this).val();
            lijstAccounts.length = 0;

                    jQuery.ajax({
                        url: "http://"+serverIp+"/getAllAccountNamesJsonP?jsonp_callback=?",
                        dataType: 'jsonp',
                        jsonp: "jsonp_callback",
                        data: {
                            featureClass: "P",
                            style: "full",
                            maxRows: 12,
                            name_startsWith: jQuery(this).val(),
                                                            crm_acc: crmAccount,
                            },
                            success: function( data ) {
                                lijstAccounts.length = 0;
                                 jQuery.map( data, function( item ) {
                                                            lijstAccounts.push(item);
                                                            jQuery('#customfield_10000').trigger(
                                                                'setSuggestions',
                                                            { result : textext.itemManager().filter(lijstAccounts, query) }
                                                            );              
                                    return {
                                        label: item.label,
                                        value: item.value    
                                    }
                                });
                            }
                        }); 
                            }
        });

jQuery('#customfield_10000').textext({
                plugins : 'autocomplete'
                }).bind('getSuggestions', function(e, data)
                    {

                        textext = jQuery(e.target).textext()[0],
                        query = (data ? data.query : '') || '';

                    });

Upvotes: 0

Views: 6411

Answers (4)

sujal
sujal

Reputation: 1050

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div class="text-wrap">
<div class="text-list">
  <div class="text-suggestion">
     <span class="text-label">Lorem</span>
  </div>
</div>
</div>
<script>
 jQuery(document).ready(function() {

        jQuery('.text-label').click(function(e){
            alert('lol');
        });
});
</script>

I think you have forgot to include jquery script try this.. copy whole script and save it in .html file then try it once

Upvotes: 2

TRR
TRR

Reputation: 1643

i don't see any problem with your code.. check the jsfiddle here, it's just the copy paste of your code. I think you don't have any jquery script included in the page. Try to include one and that should solve your issue

in the jsfiddle i included Jquery 1.7.2.

Upvotes: 1

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<div class="text-wrap">
<div class="text-list">
  <div class="text-suggestion">
     <span class="text-label">Lorem</span>
  </div>
</div>
</div>
<script>
 jQuery(document).ready(function() {

        jQuery('.text-label').click(function(e){
            alert('lol');
        });
});
</script>

Works fine with me. Have you missed the jquery library or the tags

Upvotes: 1

AlphaApp
AlphaApp

Reputation: 635

Your query needs to be within <script> tags. Also add quotes as needed.

<div class="text-wrap">
<div class="text-list">
  <div class="text-suggestion">
     <span class="text-label">Lorem</span>
  </div>
</div>
</div>
<script type="text/javascript">
 jQuery(document).ready(function() {
    $('.text-label').click(function(e)){
        alert('lol');
    }
});
</script>

Upvotes: 3

Related Questions