0

I have a select with option value of *|||*. When I split this value it seems the * cannot be stored in label id. If I change the value to xxx|||yyy the value is stored. This is some of my script:

var tujuan = $(this).val().split('|||');
var val_t  = tujuan[0];
var txt_t  = tujuan[1];

txt_tujuan  = "<label id='"+val_t+"' class='label label-primary lbl_txt' cursor:pointer;'>";
txt_tujuan += txt_t
txt_tujuan += "</label>";

$('#d_tujuan').find('label').each(function(){
  curr_label = $(this).attr('id');

  alert(curr_label);
});
Shiladitya
  • 11,210
  • 15
  • 22
  • 33
ashura91
  • 443
  • 2
  • 14
  • `"*|||*".split('|||');` returns `["*", "*"]`. Are you sure it's the value you are expecting? Also note that `"*"` is **not** a [valid value](https://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html) for an HTML id attribute. Along with this id's must be unique, so they both can't be `"*"` – Spencer Wieczorek Oct 13 '17 at 03:18
  • yes. I that result is what I expected. so, in the `label id` and `label text` has `*` as its value – ashura91 Oct 13 '17 at 03:20
  • @ashura91 In `id` you can't have special characters except `_` (underscore) and `-`(hypen) – Shiladitya Oct 13 '17 at 03:21
  • [What are valid values for the id attribute in HTML?](//stackoverflow.com/q/70579) – Tushar Oct 13 '17 at 03:22
  • ok guys. thank you so much for responding my question. should I delete this question or what? – ashura91 Oct 13 '17 at 03:24
  • @SpencerWieczorek well, I tried to create unique label. So, I store the value in id – ashura91 Oct 13 '17 at 03:26
  • you can store unique value in html tag using valid `data-*` attribute, for example: `` – Taufik Nur Rahmanda Oct 13 '17 at 03:52

0 Answers0