Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

Wednesday, February 15, 2023

Rename element id

 

function renameCheckboxId(){
var o = $('input[name="rdoPenentuArasTanah"]');
$.each(o, function(index, value) {
// Rename check id
jQuery(this).attr("id","rdoPenentuArasTanah_"+(index+1));
});
}

Friday, July 17, 2020

Access append element using JQuery


$(document).ready(function(){
  $('body').on('click', '#yourelementid', function() {
     alert("click");
  });
});

Saturday, July 8, 2017

Add onchange event to dropdown list



<label class="control-label">Parlimen</label><br />

<?php
echo dropDownList("id_parlimen", "id_parlimen", "", "parlimen", "kod_parlimen", "parlimen", $kodParlimen, "id_negeri=".$id_negeri, "parlimen","query_data_dun('maklumat/include/get_dun.php','id_dun')");
?>

<!-- To add onchange event to id_parlimen dropdown list -->
<script type="text/javascript">
 $("#id_parlimen").on("change", function(event) {
  query_data_dun('maklumat/include/get_dun.php','id_dun');
 } );
</script>

Sunday, March 26, 2017

Enable/Disable input type Button using JQuery



HTML
<input type="button" disabled value="Submit" id="button-submit"/>

JavaScript
//To enable
$('#button-submit').button('enable');

//To disable
$('#button-submit').button('disable);

Thursday, March 16, 2017

Set "checked" to checkbox



jQuery 1.6+

Use the new .prop() method:
$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);

jQuery 1.5.x and below

The .prop() method is not available, so you need to use .attr().
$('.myCheckbox').attr('checked', true);
$('.myCheckbox').attr('checked', false);
Note that this is the approach used by jQuery's unit tests prior to version 1.6 and is preferable to using
$('.myCheckbox').removeAttr('checked');
since the latter will, if the box was initially checked, change the behaviour of a call to .reset() on any form that contains it - a subtle but probably unwelcome behaviour change.
For more context, some incomplete discussion of the changes to the handling of the checkedattribute/property in the transition from 1.5.x to 1.6 can be found in the version 1.6 release notes and the Attributes vs. Properties section of the .prop() documentation.

Any version of jQuery

If you're working with just one element, you can always just modify the HTMLInputElement's .checked property:
$('.myCheckbox')[0].checked = true;
$('.myCheckbox')[0].checked = false;
The benefit to using the .prop() and .attr() methods instead of this is that they will operate on all matched elements.

Friday, January 20, 2017

Enabled/Disabled dropdown list using JQuery



To enable
$("#dropdownId").attr("disabled",false);

To disable
$("#dropdownId").attr("disabled",true);

Tuesday, January 17, 2017

Sunday, January 8, 2017

Get anchor text/href upon onclick using jQuery



Note: Apply the class info_link to any link you want to get the info from.
<a class="info_link" href="~/Resumes/Resumes1271354404687.docx">
    ~/Resumes/Resumes1271354404687.docx
</a>
For href:
$(function(){
  $('.info_link').click(function(){
    alert($(this).attr('href'));
    // or alert($(this).hash();
  });
});
For Text:
$(function(){
  $('.info_link').click(function(){
    alert($(this).text());
  });
});