Sunday, 15 January 2012

JQuery Identifier Name Limitations -



JQuery Identifier Name Limitations -

i have button on html page generated php:

<button type="button" id="kredi-cekim-talep-sil-button-cysdltvqna6u0z600fpj4crsiwllzgrjmlprw/t/j2nujh4e0s0+3a4u7xqzfsdq7+pofzbahreklffs4lsyjw==" class="btn btn-labeled btn-danger" data-loading-text="iptal ediliyor..."><span class="btn-label"><i class="glyphicon glyphicon-remove"></i></span>İptal et</button> <script>$('#kredi-cekim-talep-sil-button-cysdltvqna6u0z600fpj4crsiwllzgrjmlprw/t/j2nujh4e0s0+3a4u7xqzfsdq7+pofzbahreklffs4lsyjw==').on('click',function(event){alert(1);kredicekimtalepsilfunc('cysdltvqna6u0z600fpj4crsiwllzgrjmlprw/t/j2nujh4e0s0+3a4u7xqzfsdq7+pofzbahreklffs4lsyjw==');});</script>

i'm writing onclick event it's generating error message below:

uncaught error: syntax error, unrecognized expression: #kredi-cekim-talep-sil-button-cysdltvqna6u0z600fpj4crsiwllzgrjmlprw/t/j2nujh4e0s0+3a4u7xqzfsdq7+pofzbahreklffs4lsyjw==

error appears when page loaded, it's not on click.

it's not jquery, it's css selector syntax that's issue (because jquery uses css selectors). id value contains characters can't utilize straight in css id selector. can either escape characters, or utilize getelementbyid:

$(document.getelementbyid('kredi-cekim-talep-sil-button-cysdltvqna6u0z600fpj4crsiwllzgrjmlprw/t/j2nujh4e0s0+3a4u7xqzfsdq7+pofzbahreklffs4lsyjw==')).on('click', function(event){ alert(1); kredicekimtalepsilfunc('cysdltvqna6u0z600fpj4crsiwllzgrjmlprw/t/j2nujh4e0s0+3a4u7xqzfsdq7+pofzbahreklffs4lsyjw=='); });

getelementbyid doesn't utilize css selectors, css selector syntax doesn't come it.

but better, probably, utilize id sticks css rules. in comment you've said:

this id generated based on string included in database. must hide user. when user clicks button ajax post executes , sending id. php page decodes again.

in situation, i'd utilize data-* attribute, this:

<button type="button" id="my-button" data-key="cysdltvqna6u0z600fpj4crsiwllzgrjmlprw/t/j2nujh4e0s0+3a4u7xqzfsdq7+pofzbahreklffs4lsyjw==" class="btn btn-labeled btn-danger" data-loading-text="iptal ediliyor..."><span class="btn-label"><i class="glyphicon glyphicon-remove"></i></span>İptal et</button>

then

$("#my-button").on('click', function(event){ alert(1); kredicekimtalepsilfunc($(this).attr("data-key")); });

note how got value pass kredicekimtalepsilfunc data-key attribute doesn't have repeated. if have several of these, utilize class on button, maybe delegated selector:

$("selector-for-container").on('click', '.delete-button', function(event){ alert(1); kredicekimtalepsilfunc($(this).attr("data-key")); });

jquery identifier limits

No comments:

Post a Comment