Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to move the cursor to a specific word in textarea?
    primarykey
    data
    text
    <p>in the textarea i have followwing lines, </p> <pre><code>hello world. &lt;h2&gt;sub heading&lt;/h2&gt; &lt;img src="" alt="image.jpg"&gt;&lt;h3&gt;Test&lt;/h3&gt; More text &lt;img src="" alt=""&gt; </code></pre> <p>i want to be able to click a button that will move the cursor to alt attribute which is empty. if there is "h" tag then are they in proper order.(there should be h1 tag first then h2 tag). if they are not proper order then move the cursor to next "h" tag.(this example move the cursor to h2 tag). at the end cursor would be move to last alt attribute. then if i click the button again cursor will move to "h2" tag again. I have the following code,</p> <pre><code>&lt;script type = "text/javascript"&gt; (function ($, undefined) { $.fn.getCursorPosition = function() { var el = $(this).get(0); var pos = 0; if('selectionStart' in el) { pos = el.selectionStart; } else if('selection' in document) { el.focus(); var Sel = document.selection.createRange(); var SelLength = document.selection.createRange().text.length; Sel.moveStart('character', -el.value.length); pos = Sel.text.length - SelLength; } return pos; } })(jQuery); function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd('character', selectionEnd); range.moveStart('character', selectionStart); range.select(); } else if(input.createTextRange){ var range = elt.createTextRange(); range.move('character', pos); range.select(); } } function setCaretToPos (input, pos) { setSelectionRange(input, pos, pos); } function nextAlt(input) { var current = input.getCursorPosition(); var search = input.val().substr( ( 0 == current ? 0 : current + 1 ) ); var pos = current + search.search(/&lt;[a-zA-Z]+(&gt;|.*?[^?]&gt;)/) + 1; if (-1 == pos) { alert("No elements found"); } else { setCaretToPos(input.get(0), pos); } } &lt;/script&gt; </code></pre> <p>text inside the textarea and the button:</p> <pre><code> &lt;textarea id="textarea"&gt; hello world. &lt;h2&gt;sub heading&lt;/h2&gt; &lt;img src="" alt="image.jpg"&gt;&lt;h3&gt;Test&lt;/h3&gt; More text &lt;img src="" alt=""&gt; &lt;/textarea&gt; &lt;br&gt; &lt;a onclick="nextAlt($('#textarea'));"&gt;Next&lt;/a&gt; </code></pre> <p>Codes above does not work in IE(need to be cross browser). it moves the cursor to different tags but i want to use different condition before placing the curosor to a specific place. for example, i want to check the order of the heading tag. if h2 and h3 being used then it should check for h1 tag and move the cursor to h2 tag. then if user click the button again it will move to the alt="" attribute(missing alternative text) not to h3 tag because order of the heading tag is ok after h2. when it reach the end if user click the button again cursor will go back to "h2" tag again. can someone please help me with that. thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload