views:

185

answers:

3

Hi ,

how can i click on a "< / span>" tag in a html page ?

like this :

<span id="_ID_">Hello There</span>

Is it possible ? Thanks

+1  A: 

inside span onclick="yourJsFunctionishere();

Oyeme
Hello , is there any way to click on tags that they have "id" only ? my span tag have no onclick event and i don't know how can i click on it !!!
Kermia
+2  A: 

I think you want to say "how can i call the click event on a span element ?". For a span element :

<span id="myId" onclick="myOnclikFunction()">Hello There</span>

In JavaScript you can simulate a click (seems work only on IE !) :

document.getElementById("myId").click();

With jQuery you can call the click event (and call the myOnclikFunction() function) on an element like this :

$('#myId').trigger("click");

or

$('#myId').click();

For information : id="_ID_" is not a HTML valid code. An id can't start by "_". It must begin with a letter A-Z or a-z (see HTML id Attribute).

gobygoba
hi , tnx . and if it start with (underline) char ? what will be happened ? because i've see a code like that . starting with _ !!
Kermia
is there any way to click on tags that they have "id" only ? my span tag have no onclick event and i don't know how can i click on it !! it's working with ajax techniques
Kermia
if it start with (underline) char, it works but it's not HTLM standard compliant (so, it could not work one day). What do you mean by "i don't know how can i click on it" ? For select a span without id, you can use with jQuery $('span'). It's select all span tags. You can call the click function on a span without onclick function, but it will do nothing !
gobygoba
As i said we have the id and it is working with ajax techniques . there's no event and no clickable thing . there is a persian website that using this technique ! Willing you see it ? Thank you
Kermia
Sorry but I do not understand. Can you explain exactly what do you want ? Do you want do something when the user click on the span ? Do you want to simulate a click on the span with JavaScript ? Maybe you want to add an onclik event with Javascript and keep the spans with the only "id" attribut ?
gobygoba
No , see the topic title please :) : *How to click on </span> Tag ? (((((Webbrowser - Delphi)))))* . i say we have a html page . this page have some Tabs that created with span tag . we want to click on Tabs (spans) but they have no onclick event such as submit buttons . but they have id . see this page please : *http://up.iranblog.com/Files7/c0f6ffffdbc94927a9b9.rar* the page have a tabpanel with 4 tabpages . Thank you
Kermia
sorry I did not understand the "Webbrowser - Delphi" :). I don't know this technologie, but I have seen this application http://delphi.dev-dz.com/codesource/navigateur.php with source http://delphi.dev-dz.com/codesource/navigateur.zip (sorry it's a frensh ressource but perhaps it's can help you). Why not use a button (or an other clickable element) ?
gobygoba
Thanks anyway...
Kermia
+1  A: 

Hi !

You can do the following :

procedure TMainFrm.ClickBtnClick(Sender: TObject);
var
 Document : IHTMLDocument2;
 SPAN, Temp : IHTMLElement;
 ElementCount, I : Integer;
begin
 if WB.Document = nil then
  begin
   MessageBox(Handle, 'First Load a Page in TWebBrowser !!', '', MB_OK+MB_ICONEXCLAMATION);
   Exit;
  end;

 if SIDEdit.Text = '' then
  begin
   MessageBox(Handle, 'Enter SPAN ID !', '', MB_OK+MB_ICONEXCLAMATION);
   Exit;
  end;

 Document := WB.Document as IHTMLDocument2;
 ElementCount := Document.all.length;
 for I := 0 to ElementCount - 1 do
  begin
   Temp := Document.all.item(I, '') as IHTMLElement;
   if (Temp.tagName = 'SPAN') and (Temp.id = SIDEdit.Text) then
    begin
     SPAN := Temp;
     Break;
    end;
  end;
 if SPAN <> nil then
  SPAN.click
 else
  MessageBox(Handle, 'No SPAN Tag with ID Entered Found !', '', MB_OK+MB_ICONINFORMATION);
end;

Put this Components on the Form :

TWebBrowser , Name : "WB" , for browsing the page

TEdit , Name : "SIDEdit" , for giving the SPAN tag ID

TBitBtn , Name : "ClickBtn" , the Code above is the OnClick Event of "ClickBtn"

I Think that the Code is Simple and Variables are understandable , if necessary tell me to explain the Code ...

There is an Example ...

Good Luck ... !

Mahmood_N
Thank you so much Mr Mehri :)
Kermia