Weird problem, and apparently not uncommon with jquery mobile. I have a two-item listview popup that is intended to allow users to switch views via <a href="someurl.com">
. Each choice is intended to display json data on the same page. I don't want the href
to take the viewer to another page, so I am trying to use event.preventdefault()
.
But after much research I still cannot prevent an href
from jumping to google.com, even though (I think) I am using event.preventdefault();
properly.
here's the relevant html:
<div data-role='popup' id='popupSwitchView' data-theme='none'>
<ul data-role='listview'>
<legend>Choose a view</legend>
<li><a href='javascript:;' data-role='button' data-transition='fade' data-mini='true' class='ui-btn-active switchview' id='ABC' name='theView' value='ABC'>ABC</a>
</li>
<li><a href='http://google.com' data-role='button' data-transition='fade' data-mini='true' class='switchview' id='DEF' name='theView' value='DEF'>DEF</a>
</li>
</ul>
</div>
... and here's the jquery:
$('#DEF').on('click', function () {
event.preventDefault();
I wondered if it's the way I'm using the selector, but I tested the selector with the same code here and it seems my selector is fine.
Chrome console isn't showing any error. Any thoughts on what I'm missing here?
EDIT
I neglected to mention that the above html and jquery are part of a php variable $html_jq
, which is echoed from another php file.
i.e., file1.php
echoes $html_jq
, which is defined in file2.php
.